Commit Graph

553 Commits

Author SHA1 Message Date
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
Robert Widmann
f807dfe9e3 Parse @_typeSequence in Generic Parameter Position
Stage in the parsing for this attribute, nothing else.

Motivated by two important reasons:

1) The pitch for variadic generics does not lay down a concrete syntax
   for variadic generic parameters.
2) Paring T... and T* needlessly complicate the lexer as we must now
   disambiguate them with respect to other internal operator characters
   (e.g. `T...>` must lex as `(T...)>` and not `T ...>`

Which itself adds another motivation

3) We need to start parsing this attribute *now* to avoid condfail'ing
   ourselves later.
2021-11-02 14:42:12 -07:00
Michael Gottesman
4cd1201bab [noImplicitCopy] Add support for marking a SILArgument as being a NoImplicitCopy argument.
I am purposely doing this in SILGen rather than at the type system level to
avoid having to have to add a bunch of boilerplate to the type system. Instead
of doing that, I am in SILGen checking for the isNoImplicitCopy bit on the
ParamDecl when we emit arguments. At that point, I set on the specific
SILArgument being emitted the bit that it is no implicit copy. In terms of
printing at the SIL level, I just printed it in front of the function argument
type like @owned, e.x.:

  func myFunc(_ x: @_noImplicitCopy T) -> T {
  ...
  }

becomes:

  bb0(%0 : @noImplicitCopy @owned $T):

Some notes:

* Just to be explicit, I am making it so that no implicit copy parameters by
  default are always passed at +1. The reason why I think this makes sense is
  that this is the natural way of working with a move only value.

* As always, one can not write no implicit copy the attribute without passing
  the flag -enable-experimental-move-only so this is NFC.

rdar://83957088
2021-11-01 09:34:38 -07:00
Erik Eckstein
8229b374b1 Performance annotations: add attributes @_noLocks and @_noAllocation 2021-10-28 18:43:14 +02:00
Michael Gottesman
a589b4a128 [moveOnly] Add an @_noImplicitCopy decl attribute and allow it to be only attached to local lets.
Some notes:

1. This is not actually wired up to any part of codegen. Instead, this PR just
has the code necessary to parse the attribute and to ensure that we use it only
on local lets. The rest will come in subsequent commits.

2. I am allowing for the attribute to be attached to generic things in Sema
since we do not have enough information in the TypeChecker to distinguish in
between structs with a type parameter but that have all non-generic stored vars
from one with generic stored vars. We can only support the later with opaque
values but the former we can support without opaque values (and is one of the
use cases we are interested in).

rdar://83957088
2021-10-26 13:00:54 -07:00
Doug Gregor
8dbfb04aed Properly serialize 'isolated' bit on function parameter declarations.
Fixes rdar://83380879.
2021-10-20 10:00:13 -07:00
Becca Royal-Gordon
354f3470a0 Add @_nonSendable decl attribute
This attribute creates an unavailable extension with a `Sendable` conformance so that the type is explicity marked as not being `Sendable`.

We also fully suppress diagnostics about unavailable Sendable conformances in Swift 5 mode code. (This is not fully developed yet—it should return to being a warning in concurrent contexts.)

The behavior when a @_nonSendable and a Sendable conformance are both on the same type is also not right yet.
2021-10-14 12:14:46 -07:00
Erik Eckstein
30a74f6284 SIL: remove the private_external SILLinkage
This was a relict from the -sil-serialize-all days. This linkage doesn't make any sense because a private function cannot be referenced from another module (or file, in case of non-wmo compilation).
2021-10-10 19:52:40 +02:00
Erik Eckstein
7849f09e52 SIL: remove the unused alloc_value_buffer, project_value_buffer and dealloc_value_buffer instructions.
Those instructions were use for the materializeForSet implementation, which was replaced by modify-coroutines.
2021-10-07 07:41:54 +02:00
Arnold Schwaighofer
8840ea6b5b Add support for parsing an availability argument in @_specialize 2021-10-05 14:46:17 -07:00