Commit Graph

32 Commits

Author SHA1 Message Date
Andrew Trick
6849b66bb3 LifetimeDependenceDiagnostics; remove a bootstrapping hack.
This temporary hack was preventing diagnostics from kicking in. This could even
result in invalid SIL after the diagnostic failed to trigger.
2025-01-13 08:30:41 -08:00
Andrew Trick
1f6a74449d [lifetime] disable trivial dependence enforcement in .swiftinterface
Briefly, some versions of Span in the standard library violated trivial
lifetimes; versions of the compiler built at that time simply ignored
dependencies on trivial values. For now, disable trivial dependencies to allow
newer compilers to build against those older standard libraries. This check is
only relevant for ~6 mo (until July 2025).
2024-12-18 16:57:16 -08:00
Andrew Trick
30d81c9e97 Update a comment; an artifact of merging. 2024-12-17 09:53:25 -08:00
Andrew Trick
3897929e4a LifetimeDependence: handle dependence on trivial values. 2024-12-16 16:09:37 -08:00
Andrew Trick
7cfe4a5660 LifetimeDependenceDiagnostics: fix global sourceLoc. 2024-12-14 22:46:55 -08:00
Andrew Trick
e871ce960d LifetimeDependenceDiagnostics pass order comments 2024-12-14 22:46:55 -08:00
Andrew Trick
f5fc17804e [NFC] SwiftCompilerSources: Add VariableScopeInstruction utility
To diagnose dependence on trivial variables.
2024-12-14 22:46:54 -08:00
Andrew Trick
0a70bdd428 LifetimeDependenceDiagnostics: handle undiagnosed mark_depends
Mark unresolved mark_depends as nonescaping so they don't leak into the
optimizer pipeline.
2024-11-18 22:31:07 -08:00
Erik Eckstein
f0633d5638 AccessUtils: support computing "constant" access paths
Add `Value.constantAccessPath`. It is like `accessPath`, but ensures that the projectionPath only contains "constant" elements.
This means: if the access contains an `index_addr` projection with a non-constant index, the `projectionPath` does _not_ contain the `index_addr`.
Instead, the `base` is an `AccessBase.index` which refers to the `index_addr`.
2024-11-04 19:26:44 +01:00
Erik Eckstein
10782cf42b SwiftCompilerSources: introduce the AST module
As the optimizer uses more and more AST stuff, it's now time to create an "AST" module.
Initially it defines following AST datastructures:
* declarations: `Decl` + derived classes
* `Conformance`
* `SubstitutionMap`
* `Type` and `CanonicalType`

Some of those were already defined in the SIL module and are now moved to the AST module.
This change also cleans up a few things:
* proper definition of `NominalTypeDecl`-related APIs in `SIL.Type`
* rename `ProtocolConformance` to `Conformance`
* use `AST.Type`/`AST.CanonicalType` instead of `BridgedASTType` in SIL and the Optimizer
2024-10-02 07:10:29 +02:00
Andrew Trick
11ba799cd4 LifetimeDependence: diagnose yield and store-to-yield. 2024-07-30 16:27:48 -07:00
Andrew Trick
ba9f12a80f LifetimeDependenceDiagnostics support for inout reassignment.
This relies on parameter dependence targets.

i.e. dependsOn in parameter position instead of result position.
2024-07-30 15:57:57 -07:00
Andrew Trick
1113c757f0 Improve function convention printing. 2024-07-29 23:44:02 -07:00
Andrew Trick
20905b2f8e LifetimeDependenceDiagnostics comment. 2024-07-29 23:44:02 -07:00
Andrew Trick
22f01a956a [SwiftCompilerSources] add BridgedOStream and debugLog().
So we can trace optimizer passes using the same output stream as the
C++ passes and don't get garbled output.
2024-07-29 21:25:43 -07:00
Erik Eckstein
638205e8c6 SwiftCompilerSources: remove references to C's stderr
Fixes a linux build error.
The `var standardError` was only used in one place for logging, which can be done with `log` anyway.
Instead of using such C library constructs directly we should bridge to higher level APIs. This is more platform independent.

https://github.com/swiftlang/swift/issues/73252
https://github.com/swiftlang/swift/issues/74701
2024-06-27 10:14:44 +02:00
Andrew Trick
279eb78d27 [windows] Temporarily guard lifetime dependence diagnostics
by -enable-experimental-feature NonescapableTypes
on the Windows platform

These passes do nothing unless the above feature flag is enabled, so
the only reason to run the pass is to exercise SwiftCompilerSources
and catch invalid SIL.

These passes rely on fundamental SwiftCompilerSources abstractions
which have not yet been tested outside of the passes. They don't yet
handle all SIL patterns, and SIL continues to evolve. We would like to
can these issues quickly as we hit them, but only if we have a way of
reproducing the failure. Currently, we don't have a way of reproducing
Windows-arm64 failures.

Workaround for:
rdar://128434000 ([nonescapable] [LifetimeDependenceInsertion]
Package resolution fails with arm64 Windows toolchain)
2024-06-20 16:51:21 -07:00
eeckstein
87a520ccb2 SwiftCompilerSources: exclude some low level file operations, which are not compilable on windows 2024-04-29 10:52:25 +02:00
Andrew Trick
f19d94ce3f Always-enable lifetime-depenence diagnostics.
-enable-experimental-feature NonescapableTypes now only controls syntax and some type inferrence features.
2024-03-27 13:57:11 -07:00
Andrew Trick
36b9ed4f9b Fix LifetimeDependenceDiagnostics to ignore closure captures
ClosureLifetimeFixup now emits mark_dependence [nonescaping]. Those should be
ignored by diagnostics. In the capture case, the dependence has already been
resolved, and may not match the SIL patterns that we expect for source-level
lifetime dependencies.

Fixes rdar://125375685 ([nonescapable] Fix lifetime-dependence diagnostics in the stdlib)
2024-03-27 13:54:27 -07:00
Andrew Trick
a0b2ae9c2c Add AccessBase.storeBorrow.
Don't treat StoreBorrow addresses as unknown bases. While they are never the base of a formal access, they are returned
as the AccessBase when querying the enclosing scope of an address.
2024-03-22 11:51:58 -07:00
Andrew Trick
08be9aebf2 LifetimeDependence cleanup logging 2024-03-22 11:51:58 -07:00
Andrew Trick
df7326d790 Fix SILType::isEscapable for box types.
SILBoxTypes have their own generic signature and substitution
map. This means that every time we query isEscapable or mayEscape, we
need to extract the type of the box's field and perform type
substitution so that the AST query only sees types from the function's
generic environment.

Fixes rdar://124179106 (Assertion failed in SIL:
(!type->hasTypeParameter() && "caller forgot to mapTypeIntoContext!"))
2024-03-07 13:34:46 -08:00
Andrew Trick
3bee32639b LifetimeDependenceDefUseWalker: use LocalVariableReachableUses. 2024-03-05 18:08:16 -08:00
Andrew Trick
d01d74e20c LifetimeDependenceDiagnostics: find the correct variable introducer. 2024-03-05 17:08:13 -08:00
Andrew Trick
8aa1d91a2c LifetimeDependence: clarify log headers 2024-03-05 17:08:13 -08:00
Meghana Gupta
12ac8042ab Handle YieldInst in LifetimeDependenceUtils 2024-02-19 15:28:04 -08:00
Andrew Trick
ecf2e36717 LifetimeDependenceDiagnostics: FIXME for @_unsafeNonEscapableResult
Reminder to add a builtin to reliably enforce this unsafe attribute.
2024-02-12 20:05:25 -08:00
Andrew Trick
274c47877f LifetimeDepenenceDiagnostics improvements
Better handling of @_unsafeNonescapableResult

Improve diagnostic clarity.
2024-02-12 09:57:14 -08:00
Andrew Trick
63413916a1 LifetimeDependenceDiagnostics; handle @_unsafeNonescapableResult. 2024-02-12 09:57:14 -08:00
Andrew Trick
3002513c4e [NFC] disable verbose lifetime diagnostics by default 2024-01-31 18:58:45 -08:00
Andrew Trick
ddceffaf3b LifetimeDependenceDiagnostics pass
Initial diagnostic pass to enforce ~Escapable types.
2024-01-30 11:45:55 -08:00