Commit Graph

2441 Commits

Author SHA1 Message Date
swift-ci
b69004d25f Merge pull request #66300 from nate-chandler/nfc/20230602/1/type-lowering-nits
[TypeLowering] NFC: Two small cleanups.
2023-06-02 12:02:07 -07:00
Nate Chandler
3e3397aba9 [TypeLowering] NFC: Print all fields. 2023-06-02 07:27:59 -07:00
Slava Pestov
fd81f8135d Merge pull request #66294 from slavapestov/pack-element-type-part-2
PackElementType changes, part 2
2023-06-02 07:32:54 -04:00
Slava Pestov
5e7a91d62a SIL: Generalize SILType::subst() to take SubstOptions 2023-06-01 19:20:11 -04:00
Meghana Gupta
73c962f190 Add pointer_escape flag to move_value/begin_borrow/alloc_box 2023-05-30 12:45:26 -07:00
Meghana Gupta
2c6139dce4 Rename SILArgument::isEscaping -> SILArgument::hasPointerEscape 2023-05-26 15:58:30 -07:00
Kuba (Brecka) Mracek
2d5f33e2e3 Add @_used and @_section attributes for global variables and top-level functions (#65901)
* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
2023-05-26 14:02:32 -07:00
Andrew Trick
3897e9a63c Merge pull request #66161 from atrick/fix-silcombine
Fix SILCombine to preserve a release of a move-only type
2023-05-26 09:44:31 -07:00
Andrew Trick
dc974e8c00 Fix SILCombine to preserve a release of a move-only type
The release needs to be preserved in case a user-defined deinit is
present in the released type. Checking for move-only is slightly
conservative.

Fixes rdar://109846094 ([move-only] SILCombine eliminates struct deinitialization)
2023-05-25 17:30:43 -07:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Allan Shortlidge
a59f5257b3 Merge pull request #66069 from tshortli/unavailable-enum-payloads
IRGen: Exclude unavailable enum cases from runtime layout calculations
2023-05-24 17:22:08 -07:00
Allan Shortlidge
ce97377218 IRGen: Exclude unavailable enum cases from runtime layout calculations.
When `-unavailable-decl-optimization=complete` is specified, exclude
unavailable enum cases from the runtime layout of enums with payloads. Without
this, the type metadata for unavailable types may be referenced by enum cases
with unavailable payloads and cause linker failures.

Resolves rdar://107483852
2023-05-22 21:49:41 -07:00
Erik Eckstein
a80d0cb8a7 remove now unused utilities
* StaticInitCloner
* some APIs in SILGlobalVariable
2023-05-22 15:34:26 +02:00
Hamish Knight
a3848c62d5 [Profiler] Don't profile generated buffers
We may want to revisit this in the future, but for
now let's avoid profiling code in generated
buffers. To make this work we'll need to come up
with a scheme for writing out the generated buffers
such that tools like `llvm-cov` can reference them.

rdar://109562235
2023-05-20 00:32:20 +01:00
Anthony Latsis
3f629315a9 Merge pull request #65731 from AnthonyLatsis/always-print-any
ASTPrinter: Turn on explicit `any` printing for everything and remove the option to disable it
2023-05-16 03:27:36 +03:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Meghana Gupta
1dc713e2f7 Add new flags "reborrow" and "escaping" to SILArgument.
"reborrow" flag on the SILArgument avoids transitive walk over the phi operandsi
to determine if it is a reborrow in multiple utilities.
SIL transforms must keep the flag up-to-date by calling SILArgument::setReborrow.
SILVerifier checks to ensure the flag is not invalidated.

Currently "escaping" is not used anywhere.
2023-05-11 12:31:37 -07:00
Alex Lorenz
49d7e041de [cxx-interop] C++ records should have address-only layout when they can't be passed in registers
This ensures that a C++ record with only ObjC ARC pointers with trivial other members is passed by value in SIL

Fixes https://github.com/apple/swift/issues/61929
2023-05-09 16:23:35 -07:00
Erik Eckstein
85aa1c12db handle debug_step in static initializers of globals and in the const expression evaluator 2023-05-08 21:23:36 +02:00
Slava Pestov
ebb99e5e84 SILGen: Wrap captures of parameter packs inside tuples
Fixes rdar://problem/108481933.
2023-05-05 22:45:03 -04:00
Allan Shortlidge
0366c42293 Merge pull request #65557 from tshortli/unavailable-decl-optimization-stub
Introduce `stub` mode for `-unavailable-decl-optimization`
2023-05-05 09:11:41 -07:00
Alexis Laferrière
957639e27c Merge pull request #65631 from xymus/types-in-silfunction-mismatch
[SIL Serialization] Print mismatching SILFunction types on crash
2023-05-04 14:09:56 -07:00
Zoe Carver
f358cbea8e Merge pull request #65578 from zoecarver/disable-rvalue-ref
[cxx-interop] Disable rvalue references. We don't support them correc…
2023-05-04 10:15:56 -07:00
Alex Lorenz
62fd801828 [interop] C++ parameter of reference type should be imported as its pointee type in Swift even if parameter's type is type alias
This finally allows std::vector.push_back to be called with the pushed value directly passed into it
2023-05-03 18:23:03 -07:00
Alexis Laferrière
9bf0b6be05 [SIL Serialization] Print mismatching SILFunction types on error
The crash on `SILFunction type mismatch` provides little information and
tends to be difficult to reproduce. Let's print some of the available
information and distinguish the two failure sites.

I'm not confident all required information is written down so we may
need to improve this further in the future. This version still crashes
the compiler, we may want a proper type-check to prevent this failure
with a clean diagnostic for the example used here.

rdar://53821031
2023-05-03 17:24:55 -07:00
Allan Shortlidge
d1416ddd56 SILGen: Stub unavailable functions.
When `-unavailable-decl-optimization=stub` is specified, insert a call to
`_diagnoseUnavailableCodeReached()` at the beginning of the function to cause
it to trap if executed at run time.

Part of rdar://107388493
2023-05-03 15:19:31 -07:00
Alex Hoppen
237c70ea9c [CodeComplete] Offer completion suggestions for default argument values inside the macro declaration
We were not type checking the default argument initializer because `MacroDecl` is not an `AbstractFucntionDecl`. Add `MacroDecl` to the list of nodes we know how to get parameters from.

rdar://108163564
2023-05-01 13:48:18 -07:00
Anton Korobeynikov
0b235a7aac [AutoDiff[ Preserve substitutions maps while calculating derivative types (#65451)
The substituon map might contain proper specialization (e.g. t_0_0 -> Double) that is required to fully specify a derivate type (e.g. during reabstraction conversion from fully specified function type to a substituted one)

Fixes #65073
2023-04-26 23:11:15 -07:00
Slava Pestov
385a7beb45 SIL: Bridge 'any Sendable' via the id-as-Any path
Fixes rdar://problem/107264240.
2023-04-25 13:53:11 -04:00
Slava Pestov
66d601cc40 SILOptimizer: Teach CSE about scalar_pack_index, dynamic_pack_index, tuple_pack_element_addr 2023-04-12 17:33:31 -04:00
Erik Eckstein
c4ae7fe9e6 move-only: support deinits which get the self argument as indirect argument
This happens for address-only move-only types.
2023-04-11 10:25:49 +02:00
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
Ravi Kandhadai
1b6d160c5c Merge pull request #65003 from ravikandhadai/main
[Constant Evaluator] Enable SILConstants::setIndexedElement function to work with aggregates containing unknown values
2023-04-07 17:27:11 -07:00
Ravi Kandhadai
e02d27c7d2 [Constant Evaluator] Enable SILConstants::setIndexedElement function
to work with aggregates containing unknown values. Such aggregates
can be generated when an instruction is skipped during constant
evaluation and its results are used to create a struct.
2023-04-06 21:41:39 -07:00
Nate Chandler
6e7a91b92d [TypeLowering] Fixed verifier variable shadowing.
To work around a build failure on MSVC,
f53e88b25b changed what was stored in the
verifier’s worklist from a `TaggedEnum<ValueDecl *, unsigned>` to two
fields `ValueDecl *` and `Optional<unsigned>` with the idea that only
one should ever be non-none.  That change failed, however, to return the
_optional_ unsigned index represented by the value in the worklist,
instead returning the actual value.  That’s a problem because the
worklist can’t contain `Optional<unsigned>` but only unsigned with
`UINT_MAX` indicating "none".

rdar://107709069
2023-04-06 08:13:24 -07:00
John McCall
e355fd8c0e Merge pull request #64951 from rjmccall/pack-expansions-lowering-verifier
Fix the type-lowering verifier to handle pack expansions
2023-04-05 22:53:30 -04:00
John McCall
e609bdfb81 Walk into pack expansions in this verifier.
Fixes rdar://107664237
2023-04-05 16:58:49 -04:00
John McCall
c11cbfa6ce [NFC] Convert this code to use canonical types 2023-04-05 16:58:49 -04:00
Doug Gregor
0e2cce59a8 Make sure we visit auxiliary declarations for symbol visitation.
SIL symbol visitation wasn't visiting top-level auxiliary declarations,
which meant that it skipped peer and freestanding macros at module
scope. This would manifest in errors of the form

    <symbol> is in the generated IR file, but not in TBD file

Fixes rdar://107426276.
2023-04-05 11:45:41 -07:00
Adrian Prantl
829491b230 Merge pull request #64551 from adrian-prantl/88274783
Rebase SILScope generation on top of ASTScope
2023-04-05 08:30:13 -07: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
John McCall
9c9671b349 Merge pull request #64887 from rjmccall/vanishing-tuple-silgen
SILGen and SIL type lowering support for vanishing tuples
2023-04-04 12:41:29 -04:00
John McCall
ecd03584da Handle vanishing tuples correctly in type lowering.
Test to follow.
2023-04-03 23:16:09 -04:00
John McCall
30817b11dd Support vanishing tuples in the the general abstraction pattern routines. 2023-04-03 23:14:47 -04: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
nate-chandler
5e0267b9b7 Merge pull request #64553 from nate-chandler/eagermove_collections
[stdlib] Collection types are eagerMove.
2023-03-30 16:16:26 -07:00
Adrian Prantl
af3b73a8ac Merge pull request #64590 from adrian-prantl/implicit-sillocation
Preserve the Implicit attribute in SILLocation. (NFC)
2023-03-30 13:46:51 -07:00
Nate Chandler
ff3ec19878 [TypeLowering] Fix lexicality check for tuples.
Use the new mechanism for looking into tuples that properly handles
packs.
2023-03-30 11:04:47 -07:00
John McCall
03f4e5629e Merge pull request #64681 from rjmccall/more-variadic-fixes
More fixes for generating SIL for variadic generics
2023-03-28 19:25:31 -04:00
Allan Shortlidge
9a1a2c3b9d Merge pull request #64644 from tshortli/strip-unavailable-code
Introduce `-unavailable-decl-optimization`
2023-03-28 08:53:48 -07:00