Commit Graph

126 Commits

Author SHA1 Message Date
Erik Eckstein
6df033b298 SIL: only use canonical substitution maps in SIL
* When constructing instructions which have substitution maps: initialize those with the canonical SubstitutionMap
* Also initialize SILFunction::ForwardingSubMap with the canonical one

Non-canonical substitution maps may prevent generic specializations.
This fixes a problem in Embedded Swift where an error is given because a function cannot be specialized, although it should.

https://github.com/swiftlang/swift/issues/83895
rdar://159065157
2025-08-29 22:31:04 +02:00
Michael Gottesman
6058b1d9bd [silgen] Change SILGen to emit ignored_user for emitIgnoredExpr and black hole initialization. 2025-01-22 21:12:36 -08:00
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Andrew Trick
a1fe258692 Update tests for new trivial moves and extend_lifetimes. 2024-07-26 08:27:48 -07:00
Nate Chandler
10ce0c6b16 [SILGen] Used move_value for lexical lets.
Instead of using begin_borrow [lexical] + copy_value.
2023-12-14 13:35:26 -08:00
Nate Chandler
9bb0187be1 [SILGen] Add begin_borrow [var_decl] lifetimes. 2023-11-28 07:26:09 -08:00
Nate Chandler
e5d87f75a8 [SIL] Add source formal type to checked_cast_br.
It is necessary for opaque values where for casts that will newly start
out as checked_cast_brs and be lowered to checked_cast_addr_brs, since
the latter has the source formal type, IRGen relies on being able to
access it, and there's no way in general to obtain the source formal
type from the source lowered type.
2023-07-27 15:04:15 -07:00
Nate Chandler
cda365ca8d [stdlib] Collection types are eagerMove.
Types that have "value semantics" should not have lexical lifetimes.
Value types are not expected to have custom deinits. Are not expected to
expose unsafe interior pointers. And cannot have weak references because
they are structs. Therefore, deinitialization barriers are irrelevant.

rdar://107076869
2023-03-30 11:04:47 -07:00
Sima Nerush
3b415f050d Sema: Allow collection downcast in cast pattern and remove the diagnostic that it is not implemented 2022-11-01 13:41:44 -07:00
Nate Chandler
3c78a0bb90 [SILGen] Only lexical types get lexical lifetimes.
Only emit `begin_borrow [lexical]` and only mark `alloc_stack`s
`[lexical]` when the variable in question's lifetime is lexical, not
eager move.
2022-08-22 15:28:00 -07:00
Pavel Yaskevich
86165291aa [TypeChecker] Change the way for-in statement in type-checked
Instead of asking SILGen to build calls to `makeIterator` and
`$generator.next()`, let's synthesize and type-check them
together with the rest of for-in preamble. This greatly simplifies
interaction between Sema and SILGen for for-in statements.
2022-05-30 23:17:41 -07:00
Nate Chandler
cf08f8878d [Test] Adapted SILGen tests. 2022-01-13 13:33:42 -08:00
Michael Gottesman
785153045b [move-operator] Start having SILGen emit lexical lifetimes and teach the optimizer how to maintain lexical lifetimes until the lexical lifetime elimination.
I am doing this so that I can use lexical lifetimes to emit diagnostics such as
the move operator diagnostics.
2021-11-29 18:02:13 -08:00
Slava Pestov
2c2d087242 Sema: More accurate VarDeclUsageChecker analysis with local functions
We used to take all the captures of a local function and treat them all
as read and write usages of vars from an outer scope. Instead, let's
refactor the analysis to walk into local functions.
2020-04-03 18:07:08 -04:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Doug Gregor
97b5a0d5fb [Type checker] Stop devirtualizing the reference to IteratorProtocol.next().
Rather than having the type checker look for the specific witness to
next() when type checking the for-each loop, which had the effect of
devirtualizing next() even when it shouldn't be, leave the formation
of the next() reference to SILGen. There, form it as a witness
reference, so that the SIL optimizer can choose whether to
devirtualization (or not).
2020-01-02 14:39:00 -08:00
Slava Pestov
53bfc767a3 SIL: Track target formal type for casts
SIL type lowering erases DynamicSelfType, so we generate
incorrect code when casting to DynamicSelfType. Fixing this
requires a fair amount of plumbing, but most of the
changes are mechanical.

Note that the textual SIL syntax for casts has changed
slightly; the target type is now a formal type without a '$',
not a SIL type.

Also, the unconditional_checked_cast_value and
checked_cast_value_br instructions now take the _source_
formal type as well, just like the *_addr forms they are
intended to replace.
2019-11-20 21:30:28 -05:00
Parker Schuh
687ff25157 Convert ForEachStmt to not use tc.callWitness().
For reference, everything else except string interpolation has been converted
not to call this method.
2019-06-28 14:20:42 -07:00
kagemiku
fbba1f7c2f Fix tests for warning messages of defer_stmt_at_block_end 2019-06-07 23:29:14 -07:00
Robert Widmann
426fe886dc [SR-8272] Drop the last remnants of LogicValue
Removes the _getBuiltinLogicValue intrinsic in favor of an open-coded
struct_extract in SIL.  This removes Sema's last non-literal use of builtin
integer types and unblocks a bunch of cleanup.

This patch would be NFC, but it improves line information for conditional expression codegen.
2018-12-19 23:14:59 -05:00
Michael Gottesman
40a09c9c21 Fixup tests for -assume-parsing-unqualified-ownership-sil => [ossa] transition. 2018-12-18 00:49:32 -08:00
Michael Gottesman
9e13779702 [ownership] Remove most -enable-sil-ownership from SILGen now that %target-swift-emit-silgen does it automatically.
I did this using a sed pattern and verified by hand that I was only touching
target-swift-emit-silgen lines.
2018-12-13 11:54:54 -08:00
Michael Gottesman
0af0d5fddc [ownership] Replace ValueOwnershipKind::Trivial with ValueOwnershipKind::Any.
In a previous commit, I banned in the verifier any SILValue from producing
ValueOwnershipKind::Any in preparation for this.

This change arises out of discussions in between John, Andy, and I around
ValueOwnershipKind::Trivial. The specific realization was that this ownership
kind was an unnecessary conflation of the a type system idea (triviality) with
an ownership idea (@any, an ownership kind that is compatible with any other
ownership kind at value merge points and can only create). This caused the
ownership model to have to contort to handle the non-payloaded or trivial cases
of non-trivial enums. This is unnecessary if we just eliminate the any case and
in the verifier separately verify that trivial => @any (notice that we do not
verify that @any => trivial).

NOTE: This is technically an NFC intended change since I am just replacing
Trivial with Any. That is why if you look at the tests you will see that I
actually did not need to update anything except removing some @trivial ownership
since @any ownership is represented without writing @any in the parsed sil.

rdar://46294760
2018-12-04 23:01:43 -08:00
John McCall
abdba1d3f4 Change the integer-literal type from Int2048 to IntLiteral.
Part of SR-290.
2018-10-31 23:14:58 -04:00
Andrew Trick
ba03bef27e Fix test cases for SILGen after removing critical edges. 2018-10-19 23:14:17 -07:00
Erik Eckstein
39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
Michael Gottesman
c599539044 [sil] Eliminate the src parameter from end_borrow.
This does not eliminate the entrypoints on SILBuilder yet. I want to do this in
two parts so that it is functionally easier to disentangle changing the APIs
above SILBuilder and changing the underlying instruction itself.

rdar://33440767
2018-09-04 16:38:24 -07:00
Michael Gottesman
126d1e4e77 [silgen] Fix tuple initialization to use destructures instead of borrow+extract+copy.
rdar://43493020
2018-08-20 21:43:47 -07:00
Victor Guerra
ffd13662d1 addressing comments on PR
- moving WARNING definition from DiagnosticsCommon.def to DiagnosticsSema.def
- improving WARNING message to better align with guidelines described in docs/Diagnostics.md as suggested by @xwu.
- adapting expected warning message in tests.
2018-07-25 23:18:41 +02:00
Victor Guerra
783ab96c03 Fixing broken tests.
Usage of 'defer' now emits a warning in some places in the tests,
so adding the corresponding 'expected-warning'.
2018-07-24 23:15:32 +02:00
Alex Hoppen
560c22b18e [tests] Verify the libSyntax tree on SILGen tests
The SILGen testsuite consists of valid Swift code covering most language
features. We use these tests to verify that no unknown nodes are in the
file's libSyntax tree. That way we will (hopefully) catch any future
changes or additions to the language which are not implemented in
libSyntax.
2018-04-27 09:33:03 -07:00
Michael Gottesman
cb80f65f1e Remove plus_zero_test,plus_one_test from lit tests since they are no longer needed.
I am going to leave in the infrastructure around this just in case. But there is
no reason to keep this in the tests themselves. I can always just revert this
and I don't think merge conflicts are likely due to previous work I did around
the tooling for this.
2018-03-21 20:49:52 -07:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00
Michael Gottesman
6f4e87ad3f [+0-all-args] Be explicit about the module-name for tests that have plus_zero_* counterparts.
Otherwise, the plus_zero_* tests will have plus_zero_* as a module name, causing
massive FileCheck problems.

The reason why I am doing it with the main tests is so that I can use it when
syncing branches/etc.

radar://34222540
2018-03-11 21:55:24 -07:00
Michael Gottesman
8dd5ea9b60 [+0-all-args] Add a space after REQUIRES: plus_one_runtime to eliminate avoidable merge conflicts when editing other parts of the file.
This helps my tooling for enabling +0.
2018-03-11 16:19:09 -07:00
Michael Gottesman
e6e55df5ea [+0-all-args] Mark all tests that will need updates for +0 as requiring a plus_one_runtime. 2018-03-10 02:37:51 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Pavel Yaskevich
6519d99736 [Mangling/ABI] NFC: Fix SILGen tests to reflect label mangling changes 2017-12-18 15:44:24 -08:00
Slava Pestov
2a0cb060f8 SILGen: Look up the callee method after evaluating arguments 2017-11-08 01:31:55 -08:00
Alex Hoppen
1c7e289b96 [Mangling] Adjust subscript mangling to not include "subscript"
Change the mangling of accessors to have a variable or subscript node
as their only child node, while subscript nodes no longer contain a decl
name.
2017-09-10 19:44:07 +02:00
Michael Gottesman
3eb4cfd7da [sil-ownership] Enable sil ownership verification on 84 more tests.
rdar://33358110
2017-08-29 19:17:25 -07:00
Slava Pestov
58b4ed26b1 Sema: Fix capture analysis for 'defer'
A 'defer' parses as a DeferStmt and an implicit FuncDecl. The
implicit FuncDecl does not have a valid source location, so
be sure to consistently use the outer function's source
location instead.

Fixes <rdar://problem/33353035> / <https://bugs.swift.org/browse/SR-5464>.
2017-07-19 15:33:30 -07:00
Andrew Trick
588b578498 [Exclusivity] Update SILGen tests for static access markers. 2017-04-24 08:32:15 -07:00
Erik Eckstein
789646a15b Demangling: Make demangled names more readable and further reduce the size of the simplified demangled names
The goal here is to make the short demangling as short and readable as possible, also at the cost of omitting some information.
The assumption is that whenever the short demangling is displayed, there is a way for the user to also get the full demangled name if needed.

*) omit <where ...> because it does not give useful information anyway

Deserializer.deserialize<A where ...> () throws -> [A]
--> Deserializer.deserialize<A> () throws -> [A]

*) for multiple specialized functions only emit a single “specialized”

specialized specialized Constructible.create(A.Element) -> Constructible<A>
--> specialized Constructible.create(A.Element) -> Constructible<A>

*) Don’t print function argument types:

foo(Int, Double, named: Int)
--> foo(_:_:named:)

This is a trade-off, because it can lead to ambiguity if there are overloads with different types.

*) make contexts of closures, local functions, etc. more readable by using “<a> in <b>” syntax
This is also done for the full and not only for the simplified demangling.

Renderer.(renderInlines([Inline]) -> String).(closure #1)
--> closure #1 in Renderer.renderInlines

*) change spacing, so that it matches our coding style:

foo <A> (x : A)
--> foo<A>(x: A)
2017-04-13 08:43:28 -07:00
Slava Pestov
94ce4c2ac3 SIL: Only give closures shared linkage if they're going to be serialized
Otherwise, we don't want them to be linkonce_odr at the LLVM level
to avoid unnecessary link-time overhead.
2017-03-31 20:26:27 -07:00
Michael Gottesman
79b225ffa8 [silgen] Fix up EnumElementPatternInitialization::emitEnumMatch to use ownership.
This commit does a few things:

1. It uses SwitchEnumBuilder so we are not re-inventing any wheels.
2. Instead of hacking around not putting in a destroy for .None on the fail
pass, just *do the right thing* and recognize that we have a binary case enum
and in such a case, just emit code for the other case rather than use a default
case (meaning no cleanup on .none).

rdar://31145255
2017-03-29 15:36:41 -07:00
Erik Eckstein
2a55b26e46 Mangling: enable new mangling for symbols 2017-03-16 12:04:08 -07:00
Michael Gottesman
d4ae7a3f8a [semantic-sil] When calling emitRValueForDecl, borrow the value before deciding whether or not to copy the value.
rdar://29791263
2017-02-15 15:29:30 -08:00
Slava Pestov
f93c59fdcb AST: Don't canonicalize replacement type in substitutions
A change was recently made to canonicalize replacement types in
GenericSignature::getSubstitutions().

This resulted in ParenType being stripped off, which triggered
the 'tuple splat' diagnostic on code that was accepted in Swift 3.0.

I believe this canonicalization step is unnecessary; we
canonicalize using a brand-new ArchetypeBuilder that has no
generic signature added to it, so this is just equivalent to a
call to getCanonicalType().

Also adding the generic signature in question to the builder is
not the right answer either; the replacement types might be
written in terms of a different generic signature, or possibly
in terms of archetypes.

Taking this out seems to have no effect except changing a few
SIL dumps to contain sugared types, which should be harmless.

Part of fixing <rdar://problem/29739905>.
2017-01-19 20:07:05 -08:00
Doug Gregor
a232b41f87 [Archetype builder] Use archetype anchors exclusively in requirements.
When enumerating requirements, always use the archetype anchors to
express requirements. Unlike "representatives", which are simply there
to maintain the union-find data structure used to track equivalence
classes of potential archetypes, archetype anchors are the
ABI-stable canonical types within a fully-formed generic signature.

The test case churn comes from two places. First, while
representatives are *often* the same as the archetype anchors, they
aren't *always* the same. Where they differ, we'll see a change in
both the printed generic signature and, therefore, it's
mangling.

Additionally, requirement inference now takes much greater
care to make sure that the first types in the requirement follow
archetype anchor ordering, so actual conformance requirements occur in
the requirement list at the archetype anchor---not at the first type
that is equivalent to the anchor---which permits the simplification in
IRGen's emission of polymorphic arguments.
2017-01-12 11:07:05 -08:00