Commit Graph

412 Commits

Author SHA1 Message Date
Kavon Farvardin
13cbe0dd15 adding the @_compilerInitialized attribute
This attribute is designed for let-bound variables whose initializing
assignment is synthesized by the compiler. This assignment is
expected to happen at some point before DefiniteInitialization has
run, which is the pass that verifies whether the compiler truly
initialized the variable.

I generally expect that this will never be a user-facing feature, and
that the synthesized assignment happens in SILGen.
2022-03-24 16:18:49 -07:00
Alexis Laferrière
93e8a359e3 [Serialization] Ignore the exported module name for XRefs
Write the real module name for XRefs in swiftmodule files instead of the
exported module name, from `export_as` declarations in module maps.
Swiftmodule files are internal details now, they should represent the
truth.

We keep using the exported module name for the extensions lookup table
as clients should still use the exported name. However we may need to
write both alternatives in the lookup table in the future if extensions
can't be found from clients not importing the exported as module.

rdar://90272035
2022-03-23 12:38:59 -07:00
Evan Wilde
aa51bdf17a Add noasync availability kind to available attr
This patch adds the `noasync` availability kind to `@available`. The
spelling is `@available(*, noasync)`.
2022-03-22 15:12:51 -07:00
Erik Eckstein
6a020f8f15 Stabilize and simplify SIL linkage and serialization
The main point of this change is to make sure that a shared function always has a body: both, in the optimizer pipeline and in the swiftmodule file.
This is important because the compiler always needs to emit code for a shared function. Shared functions cannot be referenced from outside the module.
In several corner cases we missed to maintain this invariant which resulted in unresolved-symbol linker errors.

As side-effect of this change we can drop the shared_external SIL linkage and the IsSerializable flag, which simplifies the serialization and linkage concept.
2022-03-09 15:28:05 +01:00
Robert Widmann
d6186c9cfb Add a DeclContext Parameter to Opened Archetype Construction
This ensures that opened archetypes always inherit any outer generic parameters from the context in which they reside. This matters because class bounds may bind generic parameters from these outer contexts, and without the outer context you can wind up with ill-formed generic environments like

<τ_0_0, where τ_0_0 : C<T>, τ_0_0 : P>

Where T is otherwise unbound because there is no entry for it among the generic parameters of the environment's associated generic signature.
2022-03-07 22:54:22 -08:00
Xi Ge
ce07ce2dbc frontend: add basic support for @_spi_available 2022-03-04 21:26:56 -08:00
Slava Pestov
a013cd2076 AST: Replace PrimaryAssociatedTypeAttr with AssociatedTypeDecl::isPrimary() flag 2022-03-03 10:15:02 -05:00
John McCall
7830d937e0 Make room in the serialization decl block for more attributes. 2022-02-28 19:10:28 -05:00
John McCall
713bb43a94 Rework the serialization schema for conformances and requirements.
We now schedule conformance emissions in basically the same way
we do for types and declarations, which means that we'll emit them
uniquely in the module file instead of redundantly at every use.
This should produce substantially smaller module files overall,
especially for modules that heavily use generics.  It also means
that we can remove all the unfortunate code to support using
different abbrev codes for them in different bitcode blocks.

Requirement lists are now emitted inline in the records that need
them instead of as trailing records.  I think this will improve
space usage, but mostly it assists in eliminating the problem
where abbrev codes are shared between blocks.
2022-02-28 17:32:00 -05:00
Pavel Yaskevich
3cab840e0c [Serialization] Serialize type of default expression
This type is going to be use to infer generic parameters at the
call site.
2022-02-21 09:59:49 -08:00
Slava Pestov
7e5d6f4cb0 AST: Rework ParameterizedProtocolTypes to store multiple argument types
For now, this is NFC since we still assume one argument elsewhere.
2022-02-18 18:22:20 -05:00
Michael Gottesman
375ce353f2 [move-function] Add a flag to alloc_stack and debug_value that states that they describe an address/value that was moved at some point locally in the function.
The main effect of this will be that in IRGen we will use llvm.dbg.addr instead
of llvm.dbg.declare. We must do this since llvm.dbg.declare implies that the
given address is valid throughout the program.

This just adds the instructions/printing/parsing/serialization/deserialization.

rdar://85020571
2022-02-14 17:56:03 -08:00
Slava Pestov
7ee83a0c22 Serialization: Round-trip the RequirementMachine's ProtocolTypeAlias records 2022-02-13 00:24:23 -05:00
Doug Gregor
3933c6dc2a Only need one bit 2022-02-11 16:00:15 -08:00
Doug Gregor
576d7f1dec Fix serialization format for the @_nonSendable attribute
Fixes rdar://87993551.
2022-02-11 15:44:39 -08:00
Allan Shortlidge
b860e762b2 AST: Introduce the @_backDeploy function attribute:
- Parse the attribute and diagnose parsing issues
- Serialize the attribute
2022-02-08 10:11:04 -08:00
Slava Pestov
aa67c8bf8a Parametrized => parameterized 2022-02-03 13:27:24 -05: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
Doug Gregor
0416ec708b Augment GenericTypeParamDecl with bits indicating they came from opaque types 2022-01-26 14:47:11 -08:00
Slava Pestov
e7e536705e AST: Introduce ParametrizedProtocolType 2022-01-26 00:11:38 -05: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
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
Erik Eckstein
5fd941eb67 Add the @exclusivity attribute.
The `@exclusivity(unchecked)` attribute can be used on variables to selectively disable exclusivity checking.
For completeness, also the `@exclusivity(checked)` variant is supported: it turns on exclusivity checking for specific variables if exclusivity enforcement is disabled by the command line option.

This new attribute is a missing implementation part of SE-0176 (https://github.com/apple/swift-evolution/blob/main/proposals/0176-enforce-exclusive-access-to-memory.md).

rdar://31121356
2022-01-25 08:06:45 +01:00
Doug Gregor
452eccab83 Remove NestedArchetypeType.
Nested archetypes are represented by their base archetype kinds (primary,
opened, or opaque type) with an interface type that is a nested type,
as represented by a DependentMemberType. This provides a more uniform
representation of archetypes throughout the frontend.
2022-01-14 21:28:21 -08:00
Doug Gregor
34506bf316 Rework OpenedArchetypeType to generalize over interface types.
Form opened archetype types based on an interface type and existential
type, rather than assuming all OpenedArchetypeType instances only
represent the root. Sink the UUID, existential type, and actual creation
of the opened archetype into the opened generic environment, so we
consistently only create new archetype instances from the generic
environment. This slims down OpenedArchetypeType and makes it work
similarly to the other archetype kinds, as well as generalizing it
to support nested types.
Sink the existential type and UUID of an
2022-01-14 21:27:14 -08:00
Doug Gregor
ac4d26d711 Generalize (Primary|Sequence)ArchetypeType to arbitrary interface types.
As another step toward eliminating NestedArchetypeType, generalize the
representation, construction, and serialization of primary and sequence
archetypes to interface types, rather than generic parameter types.
2022-01-14 21:26:28 -08:00
Doug Gregor
6ae6ab901a Make opaque type archetypes root- and nested-type agnostic 2022-01-14 21:26:10 -08:00
Holly Borla
ee331a8c01 [Type System] Enable explicit existential types. 2022-01-13 19:31:35 -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
Zoe Carver
53ab3ef966 Merge pull request #34993 from zoecarver/cxx/cxxmethod-representation
[cxx-interop] Add SIL function representation cxx_method; Support extending C++ types.
2022-01-06 17:54:12 -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
Doug Gregor
73ae727e5f Fix (de-)serialization of opaque result types for structural opaque types.
Serialize the ordinal value of OpaqueTypeArchetypeTypes and properly
set the interface type of OpaqueTypeDecl on deserialization.
2021-12-24 22:59:37 -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
Evan Wilde
86d4f83de9 Make @main non-simple
We want to control when the attribute gets emitted so we need to make
the attribute non-simple.
2021-12-16 16:31:15 -08:00
Holly Borla
260654cd33 [Serialization] Bump the module format version for existential any
serialization.
2021-12-09 23:15:02 -08:00
Holly Borla
00a4629515 Revert "NFC: Remove the now dead ProtocolDecl::existentialTypeSupported()"
This reverts commit eb1bd07bb3.
2021-12-09 23:15:02 -08:00
Holly Borla
445a856652 [Type System] Introduce a dedicated type to represent existential types.
The new type, called ExistentialType, is not yet used in type resolution.
Later, existential types written with `any` will resolve to this type, and
bare protocol names will resolve to this type depending on context.
2021-12-09 23:14:50 -08:00
Evan Wilde
691cf1925d Merge branch 'main' into ewilde/concurrency/unavailablefromasync-messages 2021-12-08 11:41:14 -08:00
Evan Wilde
34fc8cd856 update module format number for message 2021-12-08 09:39:24 -08:00
Evan Wilde
3a13721eae Add optional message to unavailablefromasync
Adding the ability to add an optional message to the unavailable from
async attribute. This can be used to indicate other possible API to use,
or help explain why it's unavailable.
2021-12-08 09:39:24 -08:00
Michael Gottesman
d74299e68d [move-function] Add a new instruction called mark_unresolved_move_addr.
This instruction is similar to a copy_addr except that it marks a move of an
address that has to be checked. In order to keep the memory lifetime verifier
happy, the semantics before the checker runs are the mark_unresolved_move_addr is
equivalent to copy_addr [init] (not copy_addr [take][init]).

The use of this instruction is that Mandatory Inlining converts builtin "move"
to a mark_unresolved_move_addr when inlining the function "_move" (the only
place said builtin is invoked).

This is then run through a special checker (that is later in this PR) that
either proves that the mark_unresolved_move_addr can actually be a move in which
case it converts it to copy_addr [take][init] or if it can not be a move, emit
an error and convert the instruction to a copy_addr [init]. After this is done
for all instructions, we loop back through again and emit an error on any
mark_unresolved_move_addr that were not processed earlier allowing for us to
know that we have completeness.

NOTE: The move kills checker for addresses is going to run after Mandatory
Inlining, but before predictable memory opts and friends.
2021-12-06 12:47:29 -08:00
Evan Wilde
ed81cf2a10 Update ModuleFormat to reflect unavailablefromasync 2021-12-01 11:04:26 -08:00
Kuba (Brecka) Mracek
c89eca6c34 Enforce consistent usage of -experimental-hermetic-seat-at-link flag (#39986)
We've recently added the -experimental-hermetic-seal-at-link compiler flag,
which turns on aggressive dead-stripping optimizations and assumes that library
code can be optimized against client code because all users of the library
code/types are present at link/LTO time. This means that any module that's
built with -experimental-hermetic-seal-at-link requires all clients of this
module to also use -experimental-hermetic-seal-at-link. This PR enforces that
by storing a bit in the serialized module, and checking the bit when importing
modules.
2021-11-30 10:44:58 -08:00
Saleem Abdulrasool
349af3707d Merge pull request #40305 from compnerd/semitruck
gardening: make c++98-compat-extra-semi an error
2021-11-30 08:18:36 -08:00
Saleem Abdulrasool
910fbee14e gardening: make c++98-compat-extra-semi an error
This cleans up 90 instances of this warning and reduces the build spew
when building on Linux.  This helps identify actual issues when
building which can get lost in the stream of warning messages.  It also
helps restore the ability to build the compiler with gcc.
2021-11-27 11:40:17 -08:00
Xi Ge
06e63896cd ModuleInterface: consume _const keyword at var and parameter decls and keep them in textual/binary modules
This is to ensure users can start adding these annotations. Type checker supports will come in later commits.

Related to pitch: https://forums.swift.org/t/pitch-compile-time-constant-values/53606

rdar://85268028
2021-11-19 22:13:23 -08:00
Robert Widmann
e7e11df927 Model Sequence Archetypes 2021-11-16 11:38:57 -08:00
Andrew Trick
17fef2fb1e Give bind_memory a token result.
Required for UnsafeRawPointer.withMemoryRebound(to:)

%token = bind_memory %0 : $Builtin.RawPointer, %1 : $Builtin.Word to $T

%0 must be of $Builtin.RawPointer type

%1 must be of $Builtin.Word type

%token is an opaque $Builtin.Word representing the previously bound types
for this memory region.
2021-11-14 22:04:46 -08:00
Robert Widmann
22405cefea Plumb the "Is Type Sequence" Bit Through the Surface AST 2021-11-08 13:48:30 -08:00
Michael Gottesman
99d87c35f8 [moveOnly] Allow for move_value to have an optional [allows_diagnostics] modifier.
This is a signal to the move value kill analysis that this is a move that should
have diagnostics emitted for it. It is a temporary addition until we add
MoveOnly to the SIL type system.
2021-11-04 17:13:29 -07:00