Commit Graph

412 Commits

Author SHA1 Message Date
Erik Eckstein
7d70a70acf SIL: add the drop_deinit instruction
his instruction is a marker for a following destroy instruction to suppress the call of the move-only type's deinitializer.
2023-04-11 10:25:48 +02:00
Adrian Prantl
158772c2ab Rebase SILScope generation on top of ASTScope.
This patch replaces the stateful generation of SILScope information in
SILGenFunction with data derived from the ASTScope hierarchy, which should be
100% in sync with the scopes needed for local variables. The goal is to
eliminate the surprising effects that the stack of cleanup operations can have
on the current state of SILBuilder leading to a fully deterministic (in the
sense of: predictible by a human) association of SILDebugScopes with
SILInstructions. The patch also eliminates the need to many workarounds. There
are still some accomodations for several Sema transformation passes such as
ResultBuilders, which don't correctly update the source locations when moving
around nodes. If these were implemented as macros, this problem would disappear.

This necessary rewrite of the macro scope handling included in this patch also
adds proper support nested macro expansions.

This fixes

rdar://88274783

and either fixes or at least partially addresses the following:

rdar://89252827
rdar://105186946
rdar://105757810
rdar://105997826
rdar://105102288
2023-04-04 15:20:11 -07:00
Michael Gottesman
43d8ab24f4 [move-only] Add a new type of mark_must_check initable_but_not_consumable.
This is used to teach the checker that the thing being checked is supposed to be
uninitialized at the mark_must_check point so that we don't put a destroy_addr
there.

The way this is implemented is that we always initially add
assignable_but_not_consumable but in DI once we discover that the assign we are
guarding is an init, we convert the assignable to its initable variant.

rdar://106525988
2023-03-31 17:32:58 -07:00
Andrew Trick
aa469544c7 ParseTestSpecification: handle multi-line strings
We need this for specifications that involve multiple components and long instruction lists.
2023-03-23 01:56:19 -07:00
Michael Gottesman
ee451f0862 [move-only] If we have a noncopyable type on an alloc_stack/alloc_box/debug_value, set the [moveable_value_debuginfo] flag.
This still does not have the complete behavior that we want since we are not yet
inserting the debug_value undef to invalidate after performing moves.

NOTE: In printed SIL, I decided to make the flag implicit if we have a
noncopyable type. This is just to reduce the bloat in SIL. If one needs this
property for a copyable type though, it is mandatory.
2023-03-19 16:05:51 -07:00
Michael Gottesman
8d12f893c2 [sil] Add a moveable_value_debuginfo field to AllocBoxInst.
Just getting parsing/serialization to work. I haven't wired it up to anything.
2023-03-19 15:50:29 -07:00
Michael Gottesman
4a309575d7 [sil] Rename [moved] flag on debug_value/alloc_stack to moveable_value_debuginfo.
This is in preparation for wiring up debug info support for noncopyable
values. Originally this flag name made sense since it was set when we performed
consume operator checking. Now I am going to use it for noncopyable types as
well. I think the new name uses_moveable_value_debuginfo actually describes what
the flag is supposed to do, tell IRGen that the value may be moved since it
needs to use moveable value debug info emission.
2023-03-19 15:38:42 -07:00
John McCall
09018a8981 [NFC] Store interface shape types in opened element environments 2023-03-15 17:25:04 -04:00
Ben Barham
e8c3706fc8 [SIL] Filter out macro decls in top level lookup
Resolves rdar://106242860.
2023-03-04 21:51:38 -08:00
Michael Gottesman
00d54ebaa8 [reference-binding] Add mark_unresolved_reference_binding to signal from SILGen to the pass to check.
Just the SIL part of this.
2023-03-03 17:14:41 -08:00
Doug Gregor
200f2340d9 [Macros] Be deliberate about walking macro arguments vs. expansions
Provide ASTWalker with a customization point to specify whether to
check macro arguments (which are type checked but never emitted), the
macro expansion (which is the result of applying the macro and is
actually emitted into the source), or both. Provide answers for the
~115 different ASTWalker visitors throughout the code base.

Fixes rdar://104042945, which concerns checking of effects in
macro arguments---which we shouldn't do.
2023-02-28 17:48:23 -08:00
Nate Chandler
ec1a5e0911 Add attr to enable lexical lifetime per function.
Enables modules to migrate to the new lifetime rules incrementally.
2023-02-18 11:59:54 -08:00
John McCall
10e487b4cf Merge pull request #63589 from rjmccall/pack_length
Add a pack_length SIL instruction for measuring the length of a pack
2023-02-12 02:40:23 -05:00
John McCall
a38478724a Add a pack_length SIL instruction for measuring the length of a pack 2023-02-10 21:50:44 -05:00
Michael Gottesman
b33535c4b6 [move-only] Add a new CheckKind::AssignableButNotConsumable.
This is used to model global_addr/ref_element_addr/escaping closure captures
where we do not want to allow the user to consume the memory (leaving the memory
in a potentially uninitialized state), but we do want to allow for the user to
assign over the memory all at once.

Consider a situation like the following:

```
@_moveOnly
struct FileDescriptor {
  var state: CInt = ...
}

final class Klass {
   var descriptor = ...
}

func consumeDescriptor(_ x: __owned FileDescriptor) {}

// Eventually both of these will point at the same class.
var globalKlass = ...
var globalKlass2 = ...

func memoryUnsafe() {
     consumeDescriptor(globalKlass.descriptor)
     consumeDescriptor(globalKlass2.descriptor)
}

func callMemoryUnsafe() {
     globalKlass2 = globalKlass()
     memoryUnsafe()
}
```

Notice how in the above in memoryUnsafe, locally the compiler has no way of
knowing that globalKlass and globalKlass2 actually point at the same class and
thus we are attempting to consume the same descriptor twice. This is even
allowed by exclusivity. If descriptor was not move only, this would be safe
since we would just copy the value when we consume it. But b/c we ar3e using
move only, we must take from the memory.
2023-02-10 13:46:19 -08:00
Michael Gottesman
85ea8b5d5b [move-only] Rename CheckKind::NoImplicitCopy -> CheckKind::ConsumableAndAssignable
This fits the name of the check better. The reason I am doing this renaming is
b/c I am going to add a nonconsumable but assignable check for
global_addr/ref_element_addr/captures with var semantics.
2023-02-10 13:46:19 -08:00
Michael Gottesman
87829aaa32 [move-only] Rename CheckKind::NoCopy -> CheckKind::NoConsumeOrAssign.
This reflects better the true meaning of this check which is that a value marked
with this check cannot be consumed on its boundary at all (when performing
let/var checking) and cannot be assigned over when performing var checking.
2023-02-10 13:46:19 -08:00
Pavel Yaskevich
8eebb5bec1 Merge pull request #63522 from xedin/revert-type-wrappers
[AST/Sema/SIL] Revert TypeWrappers feature functionality
2023-02-09 09:27:18 -08:00
Erik Eckstein
cef6ef9a84 SIL: add a debug_step instruction
This instruction can be inserted by Onone optimizations as a replacement for deleted instructions to
ensure that it's possible to single step on its location.
2023-02-09 06:50:05 +01:00
Pavel Yaskevich
e0bf2ff854 [SIL/DI] NFC: Remove TypeWrappers feature functionality 2023-02-08 10:14:29 -08:00
John McCall
dcf90ba3f3 Merge pull request #63512 from rjmccall/tuple_pack_element_addr
Add the tuple_pack_element_addr SIL instruction
2023-02-08 11:48:23 -05:00
Anton Korobeynikov
d2e022d5b4 Remove linear map structs and use plain tuples instead. (#63444)
The changes are intentionally were made close to the original implementation w/o possible simplifications to ease the review

Fixes #63207, supersedes #63379 (and fixes #63234)
2023-02-08 07:42:54 -08:00
John McCall
159c653780 Add the tuple_pack_element_addr SIL instruction.
This allows dynamically indexing into tuples.  IRGen not yet
implemented.

I think I'm going to need a type_refine_addr instruction in
order to handle substitutions into the operand type that
eliminate the outer layer of tuple-ness.  Gonna handle that
in a follow-up commit.
2023-02-07 23:22:35 -05:00
John McCall
27142e42f6 Add SIL instructions to get and set pack elements 2023-02-07 01:10:15 -05:00
John McCall
6bf9ac858b Add instructions to allocate and deallocate packs.
Having added these, I'm not entirely sure we couldn't just use
alloc_stack and dealloc_stack.  Well, if we find ourselves adding
a lot of redundancy with those instructions (e.g. around DI), we
can always go back and rip these out.
2023-01-31 22:39:34 -05:00
John McCall
c491d25d06 Fix printing and implement parsing of opened element archetypes in SIL
Also, fix a couple places that were checking for opened existentials
to check for any local archetype.
2023-01-31 19:54:31 -05:00
John McCall
5dd6c4ee5f [NFC] Pass SIL-specific type resolution state abstractly into Sema
This is in preparation for parsing pack element archetypes.
2023-01-31 19:54:31 -05:00
swift-ci
281088eb73 Merge pull request #63204 from meg-gupta/ptrauthcodegenpr
Initial support for ptrauth qualified function pointers in C
2023-01-25 22:19:34 -08:00
Meghana Gupta
ba052abec1 Add signed access enforcement to begin_access
This will be used for supporting imported c function pointers with custom __ptrauth qualifier.
2023-01-25 14:03:15 -08:00
John McCall
374c202b99 Add SIL instructions to generate pack indices 2023-01-19 23:57:22 -05:00
John McCall
37baf9b2dc Add a SIL instruction to open a pack as an element archetype
IRGen not yet done.
2023-01-11 03:11:30 -05:00
Erik Eckstein
fbe83d50fb SILPrinter: improve printing of debug locations
* Indicate auto-generated locations: instead of "loc", print "loc *" for auto-generated locations
* Print the debug location and scope of SILFunctions
2023-01-02 13:52:21 +01:00
Pavel Yaskevich
b83b0943b5 [SILDeclRef] RuntimeMetadata: Add a special kind for runtime attribute generator
A new `RuntimeAttributeGenerator` is used to reference runtime
attribute generator functions synthesized by SILGen.
`#function` magic literal points to the declaration that declaration
attribute is attached to.
2022-12-20 09:45:01 -08:00
Pavel Yaskevich
3fb69b3c3c [SIL] SILFunction: Add runtime accessible function attribute
This attribute indicates that the given SILFunction has to be
added to "accessible functions" section and could be looked up
at runtime using a special API.
2022-12-20 09:33:44 -08:00
Pavel Yaskevich
84c2ff6445 [SILDeclRef] Make it possible to identify references to runtime accessible entities
`asRuntimeAccessible` is going to be coupled with a flag on `SILFunction`
and would allow IRGen to emit such functions into a special section.
2022-12-20 09:33:44 -08:00
Michael Gottesman
6fff307328 Merge pull request #62592 from gottesmm/pr-cbfd912fd4d58ff272d3f1fe4ceb8cf02589da9a
[sil] Add a new attribute called @closureCaptured to SILFunctionArguments that are closure capture arguments.
2022-12-15 01:14:46 -08:00
John McCall
6d4588c40b Change SIL to track all LocalArchetypes and not just OpenedArchetypes. 2022-12-14 19:43:23 -05:00
Michael Gottesman
9e44011e4d [sil] Add a new attribute called @closureCaptured to SILFunctionArguments that are closure capture arguments.
I am adding this to make it easy to determine if a SILFunction that is not inout
aliasable is captured. This is useful when emitting certain types of
diagnostics like I need to emit with move only.
2022-12-14 15:16:43 -08:00
Hamish Knight
d59ff45468 [Profiler] Track the parent SourceFile for a SILCoverageMap
This tracks the source file that the profiled
entity was defined in.
2022-12-06 14:28:34 +00:00
swift-ci
40547a1483 Merge pull request #62313 from tshortli/parse-sil-has-symbol
SIL: Add parser support for `has_symbol` instructions
2022-11-30 02:44:17 -08:00
Allan Shortlidge
3e79784ff3 SIL: Add parser support for has_symbol instructions. 2022-11-29 23:47:43 -08:00
swift-ci
fbb1c0f011 Merge pull request #62181 from nate-chandler/nfc/20221118/1
[SILDebugInfo] Small tweaks.
2022-11-29 22:48:53 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Nate Chandler
c4e3f411ee [Textual SIL] Recognize auto gen'd locations. 2022-11-18 08:42:45 -08:00
Xi Ge
c5a7eff0c9 Merge pull request #62147 from tshortli/has-symbol-sil-instruction 2022-11-18 04:34:24 -08:00
Allan Shortlidge
0a24042cdd SIL: Introduce the has_symbol SIL instruction. 2022-11-16 16:07:26 -08:00
Robert Widmann
4c162b2aeb Delete libSyntax 2022-11-16 14:52:28 -08:00
Nate Chandler
ed623d7b64 [NFC] Shortened SIL [init] flag.
Instead of writing out [initalization] for some instructions, use [init]
everywhere.
2022-10-27 10:38:54 -07:00
Nate Chandler
ab35362056 [SIL] Added new test_specification instruction.
The new instruction exists only to be used in tests.  The idea is to
specify tests that ought to be run "in the context" of the containing
function.
2022-10-11 17:15:13 -07:00
Erik Eckstein
66f07fe3da Swift SIL: rework function effects and add function side-effects
So far, function effects only included escape effects.
This change adds side-effects (but they are not computed, yet).
It also involves refactoring of the existing escape effects.
Also the SIL effect syntax changed a bit. Details are in docs/SIL.rst
2022-10-05 07:38:11 +02:00