Skip to content

SIL: add mark_dependence_addr #80263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 26, 2025
Merged

SIL: add mark_dependence_addr #80263

merged 4 commits into from
Mar 26, 2025

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Mar 25, 2025

SIL: add mark_dependence_addr

And support mark_dependence_addr in SIL passes.

Necessary whenever an addressable value depends on another value. We will need dataflow to determine the lifetime of the base.

@atrick atrick marked this pull request as ready for review March 26, 2025 00:01
@atrick
Copy link
Contributor Author

atrick commented Mar 26, 2025

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Mar 26, 2025

@swift-ci benchmark

@atrick
Copy link
Contributor Author

atrick commented Mar 26, 2025

@swift-ci test source compatibility

@atrick
Copy link
Contributor Author

atrick commented Mar 26, 2025

@swift-ci smoke test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm totally confused now. The old mark_dependence can have address operands, right? What's the difference to the new mark_dependence_addr?

UnsafePointer) or pointer escape (unknown use).
The result is the forwarded value of `%value`. If `%value` is an
address, then result is also an address, and the semantics are the
same as the non-address form: the dependency is on any value derived
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel we need a definition what "derived" means.
In your example you say that a loaded value is a derived value. But what e.g. if the loaded value is stored again to another memory location. Is this "derived" as well? What about copied values? Etc.

mark_dependence_addr [nonescaping] %address : $*T on %base : $Builtin.NativeObject
```

The in-memory value at `%address` depends on the value of `%base`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference to mark_dependence with an address operand?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last time we discussed this, there wasn't any confusion. The documentation is as precise as I can make it. sounds like we just need to revise the wording or the examples as a follow up.

@atrick
Copy link
Contributor Author

atrick commented Mar 26, 2025

source-compat ObjectMapper is failing on main.

@atrick atrick merged commit 97b249b into swiftlang:main Mar 26, 2025
7 of 8 checks passed
@atrick atrick deleted the markdep-addr branch March 26, 2025 17:33
beccadax added a commit to beccadax/swift that referenced this pull request Apr 5, 2025
When a C enum has multiple constants with the same value, ClangImporter selects one of them to import as an `EnumElementDecl` and imports the others as `VarDecl` “aliases” of that one. This helps preserve the invariant that each case of an enum has a unique raw value and is distinct for exhaustiveness checking.

However, a bug in that logic could sometimes cause the canonical case to be imported *twice*—once as an `EnumElementDecl` and again as a `VarDecl` alias. In this situation, the `EnumElementDecl` was not added to the enum’s member list, resulting in a malformed AST. This bug has apparently been present since early 2017 (!), but it seems to have been harmless until recently, when the `ComputeSideEffects` SIL pass recently became sensitive to it (probably because of either swiftlang#79872 or swiftlang#80263).

Correct this problem by modifying the memoization logic to retrieve the canonical case’s clang-side constant so the subsequent check will succeed. Additionally change a variable name and add comments to help clarify this code for future maintainers.

In lieu of adding new unit tests, this commit adds a (slightly expensive) conditional assertion to catch this kind of AST malformation. There are actually about twenty tests that will fail with just the assertion and not the fix, but I’ve updated one of them to enable the assertion even in release mode.

Fixes rdar://148213237. Followup to swiftlang#80487, which added related assertions to the SIL layer.
beccadax added a commit to beccadax/swift that referenced this pull request Apr 11, 2025
When a C enum has multiple constants with the same value, ClangImporter selects one of them to import as an `EnumElementDecl` and imports the others as `VarDecl` “aliases” of that one. This helps preserve the invariant that each case of an enum has a unique raw value and is distinct for exhaustiveness checking.

However, a bug in that logic could sometimes cause the canonical case to be imported *twice*—once as an `EnumElementDecl` and again as a `VarDecl` alias. In this situation, the `EnumElementDecl` was not added to the enum’s member list, resulting in a malformed AST. This bug has apparently been present since early 2017 (!), but it seems to have been harmless until recently, when the `ComputeSideEffects` SIL pass recently became sensitive to it (probably because of either swiftlang#79872 or swiftlang#80263).

Correct this problem by modifying the memoization logic to retrieve the canonical case’s clang-side constant so the subsequent check will succeed. Additionally change a variable name and add comments to help clarify this code for future maintainers.

In lieu of adding new unit tests, this commit adds a (slightly expensive) conditional assertion to catch this kind of AST malformation. There are actually about twenty tests that will fail with just the assertion and not the fix, but I’ve updated one of them to enable the assertion even in release mode.

Fixes rdar://148213237. Followup to swiftlang#80487, which added related assertions to the SIL layer.
beccadax added a commit to beccadax/swift that referenced this pull request Apr 15, 2025
When a C enum has multiple constants with the same value, ClangImporter selects one of them to import as an `EnumElementDecl` and imports the others as `VarDecl` “aliases” of that one. This helps preserve the invariant that each case of an enum has a unique raw value and is distinct for exhaustiveness checking.

However, a bug in that logic could sometimes cause the canonical case to be imported *twice*—once as an `EnumElementDecl` and again as a `VarDecl` alias. In this situation, the `EnumElementDecl` was not added to the enum’s member list, resulting in a malformed AST. This bug has apparently been present since early 2017 (!), but it seems to have been harmless until recently, when the `ComputeSideEffects` SIL pass recently became sensitive to it (probably because of either swiftlang#79872 or swiftlang#80263).

Correct this problem by modifying the memoization logic to retrieve the canonical case’s clang-side constant so the subsequent check will succeed. Additionally change a variable name and add comments to help clarify this code for future maintainers.

In lieu of adding new unit tests, this commit adds a (slightly expensive) conditional assertion to catch this kind of AST malformation. There are actually about twenty tests that will fail with just the assertion and not the fix, but I’ve updated one of them to enable the assertion even in release mode.

Fixes rdar://148213237. Followup to swiftlang#80487, which added related assertions to the SIL layer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants