Commit Graph

167 Commits

Author SHA1 Message Date
Hamish Knight
de7e5efed6 [SILGen] Add SILDeclRef for main entry-point
Allow SILDeclRef to refer to the main program
entry-point, which will either be for a main
SourceFile, or a synthetic main such as an `@main`
decl. Adjust the various SILDeclRef related
functions to handle this new case, and change the
emission to go through `emitFunctionDefinition`.

This change will allow the entry-point for an `@main`
decl (and eventually a main SourceFile) to be
emitted on-demand from its symbol name.
2021-04-26 11:42:32 +01:00
Hamish Knight
e4624aac5d [SIL] Allow SILDeclRef to store a FileUnit
This will be used to represent the entry-point
for a main SourceFile.
2021-04-26 11:42:32 +01:00
Holly Borla
648c5753df [SILGen] Teach SILGen to emit property wrapper generator functions that
take in a projected value.
2021-02-25 18:35:14 -08:00
Joe Groff
5087e411c2 SILGen: Implement native-to-foreign thunks for async methods.
Bridging an async Swift method back to an ObjC completion-handler-based API requires
that the ObjC thunk spawn a task on which to execute the Swift async API and pass
its results back on to the completion handler.
2020-12-08 10:04:40 -08:00
Erik Eckstein
6f5cffbcb9 Mangling: add support for mangling the body-function of asyncHandlers
We don't introduce a new mangling here.
To distinguish the names of the original asyncHandler function and it's generated "body-function", we just mangle the body-function with an async attribute, i.e. as if it was declared as async.
This change is mostly to pass information to the ASTMangler to mangle a not async function as "async".
2020-12-01 08:42:56 +01:00
Arnold Schwaighofer
d6d79c66aa Merge two fields into a PointerUnion in SILDeclRef to save space 2020-10-12 09:19:29 -07:00
Arnold Schwaighofer
b994bf3191 Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a
generic function in a library.

The following definition provides a pre-specialized entry point for
`genericFunc(_:)` for the parameter type `Int` that clients of the
library can call.

```
@_specialize(exported: true, where T == Int)
public func genericFunc<T>(_ t: T) { ... }
```

Pre-specializations of internal `@inlinable` functions are allowed.

```
@usableFromInline
internal struct GenericThing<T> {
  @_specialize(exported: true, where T == Int)
  @inlinable
  internal func genericMethod(_ t: T) {
  }
}
```

There is syntax to pre-specialize a method from a different module.

```
import ModuleDefiningGenericFunc

@_specialize(exported: true, target: genericFunc(_:), where T == Double)
func prespecialize_genericFunc(_ t: T) { fatalError("dont call") }

```

Specially marked extensions allow for pre-specialization of internal
methods accross module boundries (respecting `@inlinable` and
`@usableFromInline`).

```
import ModuleDefiningGenericThing
public struct Something {}

@_specializeExtension
extension GenericThing {
  @_specialize(exported: true, target: genericMethod(_:), where T == Something)
  func prespecialize_genericMethod(_ t: T) { fatalError("dont call") }
}
```

rdar://64993425
2020-10-12 09:19:29 -07:00
Hamish Knight
cb099454d6 Allow SILGen to emit only a specific set of SILDeclRefs
Extend ASTLoweringDescriptor to store a set of
SILDeclRefs to emit through `emitFunctionDefinition`.
2020-09-15 19:20:11 +01:00
David Zarzycki
46a315e4a3 Merge pull request #32645 from davezarzycki/pr32645
NFC: Make SILType.h and SILDeclRef.h not depend on SIL/*.h
2020-07-01 11:37:33 -04:00
Dan Zheng
b9341c8713 [AutoDiff] Fix protocol witness SILGen for @differentiable class methods. (#32639)
During protocol witness SILGen for `@differentiable` class methods,
replace the `AutoDiffDerivativeFunctionIdentifier` generic signature
with the witness thunk substitution map's generic signature.

Resolves TF-1180: vtable SIL verification error.
2020-07-01 08:34:18 -07:00
David Zarzycki
fae2c19edb NFC: Make SILType.h and SILDeclRef.h not depend on SIL/*.h
SILType and SILDeclRef do not actually need anything from SIL/*.h. Also,
a few dependencies can be pushed out of the headers into cpp files to
speed up incremental rebuilds.
2020-07-01 08:05:58 -04:00
Arnold Schwaighofer
abf65bb143 IRGen: Use the right descriminator for AutoDiffDerivativeFunctions
Fixes the failure in AutoDiff/validation-test/forward_mode.swift on
arm64e.

rdar://64192250
2020-06-15 15:28:41 -07:00
Joe Groff
bba87cdc10 SIL: Fix witness visibility hack to handle non-serialized declarations.
We have a hack to handle "public" declarations in extensions to internal protcols that are
intended as default implementations for a public protocol that the internal protocol refines.
This hack failed to trigger for synthesized declarations with shared linkage, such as
automatically generated `read` coroutines, causing a visibility assertion failure where we would
try to refer to the non-serializable synthesized declaration from the witness thunk we would
normally consider serialized. Fixes rdar://problem/55846638.
2020-04-28 15:53:08 -07:00
Dan Zheng
11551e13d0 [AutoDiff] NFC: formatting. (#30573)
Run `clang-format` on changes in https://github.com/apple/swift/pull/30564.
2020-03-22 21:30:33 -07:00
Dan Zheng
723b2d2cbe [AutoDiff upstream] Add derivative function witness/vtable entry SILGen. (#30569)
`@differentiable` attribute on protocol requirements and non-final class
members now produces derivative function entries in witness tables and vtables.

This enables `witness_method` and `class_method` differentiation.

Existing type-checking rules:

- Witness declarations of `@differentiable` protocol requirements must have a
  `@differentiable` attribute with the same configuration (or a configuration
  with superset parameter indices).
  - Witness table derivative function entries are SILGen'd for `@differentiable`
    witness declarations.

- Class vtable derivative function entries are SILGen'd for non-final
  `@differentiable` class members.
  - These derivative entries can be overridden or inherited, just like other
    vtable entries.

Resolves TF-1212.
2020-03-22 16:59:01 -07:00
Dan Zheng
aab622e913 [AutoDiff upstream] Add derivative function SILDeclRefs. (#30564)
`@differentiable` attribute on protocol requirements and non-final class members
will produce derivative function entries in witness tables and vtables.

This patch adds an optional derivative function configuration
(`AutoDiffDerivativeFunctionIdentifier`) to `SILDeclRef` to represent these
derivative function entries.

Derivative function configurations consist of:
- A derivative function kind (JVP or VJP).
- Differentiability parameter indices.

Resolves TF-1209.
Enables TF-1212: upstream derivative function entries in witness tables/vtables.
2020-03-22 11:50:29 -07:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Brent Royal-Gordon
e01ce6ccec Fix property wrapper profiling bug 2019-10-14 15:59:39 -07:00
Doug Gregor
ab5d161c05 [SILGen] Separate the initialization of a wrapped property from a wrapped value
Teach SILGen to emit a separate SIL function to capture the
initialization of the backing storage type for a wrapped property
based on the wrapped value. This eliminates manual code expansion at
every use site.
2019-09-24 09:11:53 -07:00
Arnold Schwaighofer
8d9b9f328b SILGen: Fix the logic of dynamic replacements for class constructors
To correctly call designated super class initializers the designated
intializer (and not the allocator) is dynamically replaceable.
Convenience allocators are dynamically replaceable as before.
2019-02-22 10:15:06 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Arnold Schwaighofer
b102c7f6b4 Parser/Sema/SILGen changes for @_dynamicReplacement(for:)
Dynamic replacements are currently written in extensions as

extension ExtendedType {
  @_dynamicReplacement(for: replacedFun())
  func replacement() { }
}

The runtime implementation allows an implementation in the future where
dynamic replacements are gather in a scope and can be dynamically
enabled and disabled.

For example:

dynamic_extension_scope CollectionOfReplacements {
  extension ExtentedType {
    func replacedFun() {}
  }

  extension ExtentedType2 {
    func replacedFun() {}
  }
}

CollectionOfReplacements.enable()
CollectionOfReplacements.disable()
2018-11-06 09:58:36 -08:00
Arnold Schwaighofer
5f4e183302 Add [dynamically_replacable] to SILFunctions
'dynamic' functions are marked as [dynamically_replaceable].
2018-11-06 09:53:21 -08:00
Doug Gregor
2246e2bf60 [SILGen] Cope with protocol requirement overrides for keypaths.
When emitting accessor calls for keypaths, make sure that we reference
protocol requirements that introduce witness table entries. Other
protocol requirements don't have the necessary dispatch thunks,
resulting in linker errors.

Fixes rdar://problem/44187969.
2018-09-09 20:13:54 -07:00
Doug Gregor
c7152f3576 [SIL] Don’t create witness table entries for overriding requirements.
SIL will not generate calls to protocol requirements that override
other protocol requirements, so all of the witness table entries for
the overriding arguments are dynamically dead. Remove them from the
witness tables entirely.

Implements rdar://problem/43870489, reducing the size of the standard
library binary by 196k.
2018-09-05 13:51:26 -07:00
Doug Gregor
0cdede2bdf [SIL] Make witness_methods always refer to a non-overriding requirement.
When forming a witness_method instruction, follow the override chain of
a protocol requirement to reach a requirement that doesn’t override any
other protocol requirement. These will be the requirements that introduce
new witness table entries.
2018-09-05 13:51:26 -07:00
Sho Ikeda
03fbd4a6de [gardening][SIL] Replace typedef with using 2018-04-05 13:53:20 +09:00
Jordan Rose
0c92fdda33 [SIL] Remove unused ResilienceExpansion from SILDeclRef (#14451)
We ended up not using this, so let's not leave it in as cruft.
No functionality change.
2018-02-07 09:41:25 -08:00
Slava Pestov
9b0f6fca53 IRGen: Emit class dispatch thunks in IRGen instead of SILGen
This allows us to re-use the same code for emitting protocol dispatch
thunks.
2018-01-15 22:38:16 -08:00
Slava Pestov
48897ded11 SIL: Remove never-emitted SILDeclRef::Kind::GlobalGetter 2018-01-14 21:39:53 -08:00
Slava Pestov
c16c2c35bf SIL: Move getOverriddenVTableEntry() from TypeLowering to SILDeclRef
There's no reason for this to be an instance method on the TypeLowering
object, because it (no longer?) uses any type lowering operations.
2017-12-18 23:28:33 -08:00
Michael Gottesman
a8b1917512 [all-+0] Add a new convention for setters: DefaultSetterConventions.
In a situation where normal arguments are +0, we want setters to still take
normal parameters at +1 since in most cases setters will be taking a parameter
that is being forwarded into to be store into a field.

Since this doesn't actually change the current ParameterConvention for setter
normal arguments, this is NFC.

rdar://34222540
2017-11-19 12:35:18 -08:00
Slava Pestov
78ad6c4577 AST: New mangling for method dispatch thunks 2017-11-11 16:31:53 -08:00
Slava Pestov
ce2a434587 SILGen: Fix bug with vtable entries for allocating initializers
Some changes I was working on uncovered a latent bug where we would
emit a class_method instruction to call an allocating initializer
that did not have a vtable entry.

Previously this wasn't caught because the only example of this in
our test suite was in test/SILGen/objc_bridging_any.swift, which
did not test with IRGen; if it did, an IRGen crash would have been
observed.

Factor out some code duplication to prevent this from happening
again, and add a SILGen test that we emit a vtable entry in this
case, and that the test case passes IRGen also.
2017-11-11 02:01:50 -08:00
Slava Pestov
ced25fb0d7 SILGen: Remove more references to the 'uncurry level' concept 2017-11-06 18:48:20 -08:00
Huon Wilson
606a3cc679 Merge pull request #9313 from huonw/symbol-list-7
TBD: ivar init/destroy, materializeForSet callbacks
2017-05-11 20:13:22 +10:00
Huon Wilson
890d348562 [SIL] ivar initializers & destroyers are never public. 2017-05-09 21:16:36 +10:00
Slava Pestov
edb1e97a35 SIL: Remove uncurryLevel from SILDeclRef
All we need to store is whether the SILDeclRef directly
references the declaration, or if it references a curry
thunk, and we already have an isCurried bit for that.
2017-05-09 00:56:35 -07:00
Huon Wilson
b59f95418c [SIL] Extract ClassVisibility from SILFunction to SubclassScope in SILLinkage. 2017-04-13 14:17:29 -07:00
Slava Pestov
8fe8b89b0f SIL: Terminology change: [fragile] => [serialized]
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.

This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
2017-03-29 16:47:28 -07:00
Slava Pestov
7aabd80898 SIL: Stub out TypeConverter::getOverriddenVTableEntry()
This replaces SILDeclRef::getBaseOverriddenVTableEntry(). It lives
in the TypeConverter because it needs to use type lowering information
to determine if the method requires a new vtable entry or not.
2017-03-24 01:53:39 -07:00
Slava Pestov
e912f27944 AST/SILGen: New mangling for vtable thunks
Simply mangling the derived method is no longer sufficient. Now also
mangle the base method, so that eventually we handle this sort of
scenario:

class Base {
  // introduces: Base.method
  func method(_: Int, _: Int) {}
}

class First : Base {
  // overrides: Base.method
  // introduces: First.method
  override func method(_: Int?, _: Int) {}
}

class Second : First {
  // overrides: Base.method, First.method
  // introduces: Second.method
  override func method(_: Int?, _: Int?) {}
}

Here, the override of Base.method by Second.method and the
override of First.method by Second.method require distinct
manglings even though the derived method (Second.method) is
the same in both cases.

Note that while the new mangling is longer, vtable thunks are
always emitted with private linkage, so with the exception of
the standard library which is built with -sil-serialize-all
they will not affect the size of dylibs.

The standard library itself has very few classes so it doesn't
matter there either.

This patch doesn't actually add any support to introduce new
vtable entries for methods that override; this is coming up
next.
2017-03-23 23:40:52 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Erik Eckstein
564ebc9e98 Small refactoring of SILDeclRef::mangle
Instead of passing a mangling prefix as a string, just pass the kind of mangling. This will ease the transition to the new mangling scheme.
NFC
2016-11-02 10:32:02 -07:00
Slava Pestov
75bd88968b SILGen: Allow extensions to define designated initializers of generic types
Previously, if a generic type had a stored property with
a generic type and an initializer expression, we would
emit the expression directly in the body of each designated
initializer.

This is a problem if the designated initializer is defined
within an extension (even in the same source file), because
extensions have a different set of generic parameters and
archetypes.

Also, we've had bugs in the past where emitting an
expression multiple times didn't work properly. While these
might currently all be fixed, this is a tricky case to test
and it would be best to avoid it.

Fix both problems by emitting the initializer expression
inside its own function at the SIL level, and call the
initializer function from each designated initializer.

I'm using the existing 'variable initializer' mangling for this;
it doesn't seem to be used for anything else right now.

Currently, the default memberwise initializer does not use
this, because the machinery for emitting it is somewhat
duplicated and separate from the initializer expressions in
user-defined constructors. I'll clean this up in an upcoming
patch.

Fixes <https://bugs.swift.org/browse/SR-488>.
2016-08-03 01:03:08 -07:00
John McCall
c2b8bb22ba Provide ways to get back to the original Clang declaration from
a SILFunction or SILGLobalVariable.

This will be used as one step towards moving IRGen off of the
global external-definitions list.
2016-05-18 11:40:58 -07:00
Michael Ilseman
8759905351 Merge remote-tracking branch 'origin' into import-as-member 2016-03-24 11:37:36 -07:00
Slava Pestov
3e2d7d40e0 SIL: Serialize bodies of local functions inside @_transparent functions
A transparent function might be deserialized and inlined into a function
in another module, which would cause problems if the function referenced
local functions.

Previously we would force local functions to have public linkage instead,
which worked, but was not resilient if the body of the transparent
function changed in the module that contained it.

Add a library evolution test ensuring that such a change is resilient
now.

Part of https://bugs.swift.org/browse/SR-267.
2016-03-24 00:50:39 -07:00