Commit Graph

2441 Commits

Author SHA1 Message Date
Nate Chandler
2ac6ea5164 [SIL] Make owned function arguments lexical.
The destroys of owned arguments must not be hoisted over deinit barriers
to respect the semantics of lexical lifetimes.  Here, owned SILValues
which are SILFunctionArguments are made to be lexical.  Code which
hoists destroys will check this field and not hoist destroys.

Allowed more RAUWing to be done with lexical values; specifically,
allowed the replacement of a non-lexical value with a lexical value if
the replacing value's lifetime wouldn't be extended as a result.

Updated tests to get owned values via applies rather than having them
passed as arguments.
2022-02-10 16:28:42 -08:00
Slava Pestov
63b98d596f Merge pull request #41184 from slavapestov/fix-typo
Change spelling of "ParametrizedProtocolType" to "ParameterizedProtocolType"
2022-02-03 21:50:54 -05:00
Zoe Carver
3308a6259d Merge pull request #41186 from zoecarver/fix-indirect-self-param
[cxx-interop] Fix crash when calling method that returns specialization of parent.
2022-02-03 14:27:49 -08:00
zoecarver
c6aee240e6 [cxx-interop] Fix crash when calling method that returns specialization of parent. 2022-02-03 10:47:00 -08:00
Slava Pestov
aa67c8bf8a Parametrized => parameterized 2022-02-03 13:27:24 -05:00
eeckstein
00b795fe11 Merge pull request #41120 from eeckstein/capture-propagate-keypaths
CapturePropagation: specialize closures which capture a constant keypath
2022-02-02 07:54:47 +01:00
Anthony Latsis
c7fd60f2dd Merge pull request #39492 from AnthonyLatsis/se-309-2
SE-309: Covariant erasure for dependent member types
2022-02-02 07:07:17 +03:00
Anthony Latsis
60c85b0108 SILGen: Handle nested opened archetypes and add tests 2022-02-02 02:10:05 +03:00
Konrad `ktoso` Malawski
67acad7b5c Merge pull request #41118 from ktoso/wip-sil-bb-names
[SIL] Allow giving debug names to SILBasicBlocks
2022-02-02 08:04:31 +09:00
Joe Groff
23557b86da Merge pull request #41111 from jckarter/infinite-type-lowering-bailout
SIL: Detect and bail out on infinite aggregates.
2022-02-01 09:19:07 -08:00
Konrad `ktoso` Malawski
d7ba6c6fc6 store std::string, print before BB identifier 2022-02-01 23:31:32 +09:00
Erik Eckstein
34d79e3799 CapturePropagation: specialize closures which capture a constant keypath
This optimizes keypath-closures, like
```
   a.map { \.x }
```
It results in a significant performance improvement for such code patterns.

rdar://87968067
2022-02-01 09:22:07 +01:00
Konrad `ktoso` Malawski
d96cb1dbaf [SIL] Allow giving debug names to SILBasicBlocks 2022-02-01 14:35:03 +09:00
Joe Groff
fe19399585 SIL: Detect and bail out on infinite aggregates.
Sema diagnoses obvious cases of value types defined in terms of themselves,
but it can't catch cases that arise as a result of generic substitution,
such as if a generic struct has a field of associated type that becomes the
same as the struct type itself. SIL may end up handling these types, even
though they can't be instantiated (the runtime will complain and crash if
the metadata is requested), either during SILGen because they were written
in source code, or as a result of generic specialization during optimization.
SIL thus can't rely on diagnostics preventing such types from appearing, so
it needs to be able to continue gracefully when they show up. Add checks
in type lowering for when a struct or enum lowering ends up depending on
itself, and generate an infinite type lowering that's opaque and address-only.

Fixes rdar://80310017
2022-01-31 14:40:18 -08:00
Michael Gottesman
68d37e142b [no-implicit-copy] Add a new instruction called MarkMustCheckInst and use it in the move checker.
This is an instruction that I am going to use to drive some of the ownership
based dataflow optimizations that I am writing now. The instruction contains a
kind that allows one to know what type of checking is required and allows the
need to add a bunch of independent instructions for independent checkers. Each
checker is responsible for removing all of its own mark instructions. NOTE:
MarkMustCheckInst is only allowed in Raw SIL since once we are in Canonical SIL
we want to ensure that all such checking has already occurred.
2022-01-29 14:49:39 -08:00
Slava Pestov
685dbadf1b Merge pull request #41052 from slavapestov/rqm-autodiff-workaround
AutoDiff: Explicitly filter out invalid requirements
2022-01-28 13:30:12 -05:00
nate-chandler
b7ecf2a2dc Merge pull request #41050 from nate-chandler/sil/move_value_lexical_restricts_motion
[SILOpt] Made lexical flag obstruct some motion.
2022-01-28 07:08:06 -08:00
Slava Pestov
bc663bb382 AutoDiff: Explicitly filter out invalid requirements
The GenericSignatureBuilder drops requirements rooted in a non-existent
generic parameter, whereas the RequirementMachine now asserts.

Filter them out to preserve the old behavior when building the
_Differentiation module with -requirement-machine-abstract-signatures=verify.
2022-01-27 22:42:40 -05:00
Nate Chandler
7d4f6ffd7d [SIL] Added isLexical to ValueBase. 2022-01-27 15:19:30 -08:00
Becca Royal-Gordon
1275e626be Merge pull request #41035 from beccadax/dont-take-this-literally
Don't import string macros with invalid UTF-8
2022-01-27 13:56:28 -08:00
Becca Royal-Gordon
4bd532ab9a Don't import string macros with invalid UTF-8
Swift string literals are only permitted to contain well-formed UTF-8, but C does not share this restriction, and ClangImporter wasn't checking for that before it created `StringLiteralExpr`s for imported macros; this could cause crashes when importing a header. This commit makes us drop these macros instead.

Although invalid UTF-8 always *did* cause a segfault in my testing, I'm not convinced that there isn't a way to cause a miscompile with a bug like this. If we somehow did generate code that fed ill-formed UTF-8 to the builtin literal init for Swift.String, the resulting string could cause undefined behavior at runtime. So I have additionally added a defensive assertion to StringLiteralInst that any UTF-8 string represented in SIL is well-formed. Hopefully that will catch any non-crashing compiler bugs like this one.

Fixes rdar://67840900.
2022-01-26 20:57:13 -08:00
nate-chandler
0472c0d83c Merge pull request #40926 from nate-chandler/sil/move_value_defined_flag
[SIL] Added lexical flag to move_value.
2022-01-26 19:58:27 -08:00
Slava Pestov
e7e536705e AST: Introduce ParametrizedProtocolType 2022-01-26 00:11:38 -05:00
Doug Gregor
20047a248f Merge pull request #41003 from DougGregor/sr-15766-async-override-thunk 2022-01-25 16:09:49 -08:00
Doug Gregor
43f1581c4b Emit a separate vtable entry + override thunk for async overrides that drop throws
Unlike with synchronous functions, an async 'throws' function and an
async non-throwing function are not ABI-compatible. This would lead to
an ABI mismatch and runtime crash when overriding an `async throws`
function with an `async` one. Deal with this ABI incompatibility by
producing an appropriate thunk.

Fixes SR-15766 / rdar://problem/88035174.
2022-01-25 11:56:24 -08:00
Erik Eckstein
f09dfc93a9 Swift SIL: escape effects for function arguments.
Store a list of argument effects in a function, which specify if and how arguments escape.
Such effects can be specified in the Swift source code (for details see docs/ReferenceGuides/UnderscoredAttributes.md) or derived in an optimization pass.

For details see the documentation in SwiftCompilerSources/Sources/SIL/Effects.swift.
2022-01-25 11:29:44 +01:00
Erik Eckstein
93f5d9f176 swift SIL: Type.getStructFields -> Type.getNominalFields
To be able to get class fields as well as struct fields
2022-01-25 11:29:25 +01:00
Erik Eckstein
beb2bd2a96 AST: support @_effects attribute with custom strings.
In addition to the predefined cases,  like "readnone", "readonly", etc. support providing a custom string, which will be parsed later.
Also, allow multiple effects attributes to be put onto a function.
2022-01-25 11:29:23 +01:00
Evan Wilde
794d0e0b9a Merge pull request #40832 from etcwilde/ewilde/async-top-level
A first pass at concurrency in top-level code
2022-01-21 13:24:51 -08:00
Nate Chandler
572510835b [SIL] Added lexical flag to move_value.
The new flag will be used to track whether a move_value corresponds to a
source-level lexical scope. Here, the flag is just added to the
instruction and represented in textual and serialized SIL.
2022-01-20 08:33:09 -08:00
swift-ci
513183633e Merge remote-tracking branch 'origin/main' into rebranch 2022-01-14 16:53:12 -08:00
Holly Borla
d146b69ccc Merge pull request #40666 from hborla/explicit-existential-fixes
[SE-0335] Enable explicit existential types.
2022-01-14 16:38:14 -08:00
swift-ci
bd79eebe19 Merge remote-tracking branch 'origin/main' into rebranch 2022-01-14 07:33:58 -08:00
Holly Borla
6cee193fc0 [Type System] When explicit existential types are enabled, wrap Error
in ExistentialType for the type of error values.
2022-01-13 19:30:44 -08:00
Nate Chandler
ceea4cf57a [AllocBoxToStack] See through borrows.
Now that alloc_boxes whose lifetimes are lexical are emitted with
begin_borrow [lexical]/end_borrow, AllocBoxToStack needs to be able to
see through those new borrow scopes in order to continue stack promoting
the same boxes that it was able to before those lexical scopes were
emitted.
2022-01-13 13:33:21 -08:00
Evan Wilde
431b6661e4 Generate async main entrypoint for top-level
This patch adds the SILGen side of generating the asynchronous main
entrypoint for top-level code. The behavior is the same as with the
asynchronous MainType entrypoint.
2022-01-12 15:40:39 -08:00
swift-ci
3a57caf542 Merge remote-tracking branch 'origin/main' into rebranch 2022-01-07 13:14:06 -08:00
Erik Eckstein
383c52aa35 SIL: rename dealloc_ref [stack] -> dealloc_stack_ref
Introduce a new instruction `dealloc_stack_ref ` and remove the `stack` flag from `dealloc_ref`.

The `dealloc_ref [stack]` was confusing, because all it does is to mark the deallocation of the stack space for a stack promoted object.
2022-01-07 16:20:27 +01:00
swift-ci
51d5b9ecb3 Merge remote-tracking branch 'origin/main' into rebranch 2022-01-06 18:12:04 -08:00
zoecarver
036361d1e4 [cxx-interop] Add SIL function representation cxx_method; Support extending C++ types.
There are three major changes here:
    1. The addition of "SILFunctionTypeRepresentation::CXXMethod".
    2. C++ methods are imported with their members *last*. Then the arguments are switched when emitting the IR for an application of the function.
    3. Clang decls are now marked as foreign witnesses.

These are all steps towards being able to have C++ protocol conformance.
2022-01-06 14:26:47 -08:00
swift-ci
20187ed5e1 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-22 14:52:56 -08:00
Andrew Trick
ec9d4b444f Add SILInstruction::getNextInstruction() and getPreviousInstruction() 2021-12-22 01:54:05 -08:00
Andrew Trick
321351c746 Add SILFunction::preserveDebugInfo() 2021-12-22 01:54:05 -08:00
swift-ci
5fae5f3f99 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-20 11:35:46 -08:00
Robert Widmann
e5bfda7c6e Merge pull request #40587 from CodaFi/substitute-teacher
Initial Semantics for Variadic Generics
2021-12-20 11:25:25 -08:00
swift-ci
a7f9d15c2e Merge remote-tracking branch 'origin/main' into rebranch 2021-12-20 06:35:32 -08:00
Erik Eckstein
c55f040308 Add a mechanism to let cross-module-optimization add additional TBD symbols.
PublicCMOSymbols stores symbols which are made public by cross-module-optimizations.
Those symbols are primarily stored in SILModule and eventually used by TBD generation and validation.
2021-12-20 11:33:02 +01:00
swift-ci
134e17c8ec Merge remote-tracking branch 'origin/main' into rebranch 2021-12-17 16:54:09 -08:00
Pavel Yaskevich
7190e9ed9f [SIL] IR: Make sure that distributed thunk is always emitted
Even if there are no uses of the thunk in the code it's still
could be accessed from remotely via distributed accessor mechanism,
so distributed thunks are always used.
2021-12-17 10:52:55 -08:00
Pavel Yaskevich
4860f90fd7 [SIL] Add new flag to SILFunction - IsDistributed
Determines whether given SILFunction represents a distributed
method or its thunk.
2021-12-17 10:52:52 -08:00