Commit Graph

2530 Commits

Author SHA1 Message Date
Xi Ge
50142f896b AST: address code review comments on isEquivalentToExtendedContext() 2020-07-01 16:22:15 -07:00
Slava Pestov
faa06bfd87 Merge pull request #32581 from slavapestov/cached-emitted-members-request
Deterministically order class members for emission
2020-06-30 00:47:33 -04:00
Slava Pestov
89b2f27b4d AST: Mark implicit destructor as synthesized to fix non-deterministic function order
We can synthesize the default init() and the implicit deinit in a class in
any order, depending on the order of primary files and how that class was
used in other primary files.

Make sure that EmittedMembersRequest puts the destructor at the end with
all other synthesized members, so that we produce the same object file in
any case.
2020-06-29 22:17:56 -04:00
Slava Pestov
c1b0c93188 Sema: Use request evaluator caching for EmittedMembersRequest 2020-06-29 22:17:56 -04:00
Alexis Laferrière
63d9acda3e [Sema] Report public use of local SPIs by the exportability checker
This change improves slightly the quality of the diagnostics and detects
the use of local SPI types on public property with a default value.
2020-06-29 11:18:04 -07:00
Rintaro Ishizaki
9044aa0376 [AST] ParamDecl::isNonEphemeral() not to evaluate InterfaceTypeRequest
'-dump-parse' for the following code used to hit an assertion failure:

  struct MyStruct {}
  _ = { (val: MyStruct) in }

Because 'isNonEphemeral()' on 'val' parameter unintentionally causes
'InterfaceTypeRequest::evaluate()'. Since 'isNonEphemeral()' inference
based on the interface type is not possible after type checking, return
'false' unless 'hasInterfaceType()'

Also:
  * Dump parameter list on 'EnumElementDecl' as well
  * Adjust the position of 'range=...' in parameter list dumping
2020-06-25 15:01:27 -07:00
Xi Ge
e45fa71ee6 AST: isEquivalentToExtendedContext() should consider use patterns of @_originallyDefinedIn
When a nominal type and its extensions coexist in the same module, mangling may
use the nominal type as the context for extension members. We should preserve this
mechanism for types marked as @_originallyDefinedIn to maintain ABI stability.

rdar://64538537
2020-06-24 12:27:53 -07:00
Robert Widmann
b9427b0a88 [NFC] Strip RequirementRepr of its TypeLocs
Now that the previous commits have removed the data dependencies on TypeLoc, remove the TypeLoc and replace it with a TypeRepr. This makes RequirementRepr a purely syntactic object once again.
2020-06-11 16:18:24 -07:00
Robert Widmann
fb8fdd9644 Replace resolveCustomAttrType with a Request 2020-06-10 19:31:41 -07:00
Robert Widmann
e1015761fb [NFC] Reduce usage of TypedPattern::getTypeLoc 2020-06-10 16:51:10 -07:00
Arnold Schwaighofer
28fba4f5e6 Merge pull request #32195 from aschwaighofer/dyn_repl_objc_method_generic_class
Mark non-foreign entry points of `@objc dynamic` methods in generic c…
2020-06-10 10:31:18 -07:00
Arnold Schwaighofer
825a2a259b Mark non-foreign entry points of @objc dynamic methods in generic classes dynamically_replaceable
```
class Generic<T> {
  @objc dynamic func method() {}
}

extension Generic {
  @_dynamicReplacement(for:method())
  func replacement() {}
}
```

The standard mechanism of using Objective-C categories for dynamically
replacing @objc methods in generic classes does not work.

Instead we mark the native entry point as replaceable.

Because this affects all @objc methods in generic classes (whether there
is a replacement or not) by making the native entry point
`[dynamically_replaceable]` (regardless of optimization mode) we guard this by
the -enable-implicit-dynamic flag because we are late in the release cycle.

* Replace isNativeDynamic and isObjcDynamic by calls to shouldUse*Dispatch and
  shouldUse*Replacement
  This disambiguates between which dispatch method we should use at call
  sites and how these methods should  implement dynamic function
  replacement.

* Don't emit the method entry for @_dynamicReplacement(for:) of generic class
  methods
  There is not way to call this entry point since we can't generate an
  objective-c category for generic classes.

rdar://63679357
2020-06-09 09:23:29 -07:00
AG
11ef9bd92f Merge pull request #32217 from bitjammer/acgarland/rdar-63120829-show-in-interface-not-underscored
[SymbolGraph] Don't consider @show_in_interface for underscored names
2020-06-08 12:21:56 -07:00
Ashley Garland
c647c11bb5 [SymbolGraph] Don't consider @show_in_interface for underscored names
The fact that a declaration has `@_show_in_interface` shouldn't be
used to decide whether something has underscored naming, which
is just one specific kind of check regarding naming only.

Move the check for this attribute out one level.

rdar://63120829
2020-06-05 16:52:35 -07:00
Hamish Knight
f57299a587 Formalize some SourceFile parsing outputs
Currently when parsing a SourceFile, the parser
gets handed pointers so that it can write the
interface hash and collected tokens directly into
the file. It can also call `setSyntaxRoot` at
the end of parsing to set the syntax tree.

In preparation for the removal of
`performParseOnly`, this commit formalizes these
values as outputs of `ParseSourceFileRequest`,
ensuring that the file gets parsed when the
interface hash, collected tokens, or syntax tree
is queried.
2020-06-03 11:03:56 -07:00
Anthony Latsis
267e32dcd8 Merge pull request #32118 from AnthonyLatsis/post-increment-cleanup
[NFC] Pre- increment and decrement where possible
2020-06-02 20:10:29 +03:00
Slava Pestov
71b2c5003f Merge pull request #31778 from slavapestov/cloned-parameter-list-source-loc
AST: Don't set source location on cloned parameter lists
2020-06-02 00:43:46 -04:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Varun Gandhi
c14e934563 [NFC] Remove redundant includes for llvm/ADT/SmallSet.h. 2020-05-31 13:07:45 -07:00
Slava Pestov
68ba9cf96c Merge pull request #32034 from slavapestov/optimize-remove-shadowed-decls
AST: Optimize removeShadowedDecls()
2020-05-29 15:39:04 -04:00
Slava Pestov
6ca148d65e AST: Optimize removeShadowedDecls()
Previously, whenever name lookup returned two declarations with the same
name, we would compute the canonical type of each one as part of the
shadowing check.

The canonical type calculation is rather expensive for GenericFunctionTypes
since it requires constructing a GenericSignatureBuilder to canonicalize
type parameters that appear in the function's signature.

Instead, let's first shard all declarations that have the same name by
their generic signature. If two declarations have the same signature, only
then do we proceed to compute their canonical type.

Since computing a canonical GenericSignature is cheaper than computing a
canonical GenericFunctionType, this should speed up name lookup of
heavily-overloaded names, such as operators.

Fixes <rdar://problem/56800097>.
2020-05-26 23:49:14 -04:00
Slava Pestov
88d8d9fabe AST: Don't set source location on cloned parameter lists 2020-05-26 22:59:08 -04:00
Arnold Schwaighofer
532f0cb865 Type substitution: When substituting SILFunctionTypes we substitute unbound Objective-C generic for bound ones
IRGen does so. So don't assert on this case.

rdar://63509292
2020-05-26 13:26:08 -07:00
Doug Gregor
8e0ec601db Merge pull request #32005 from DougGregor/function-builder-infer
[Function builders] Infer function builder from a protocol requirement.
2020-05-26 10:59:42 -07:00
Doug Gregor
bf7eea08da [Function builders] Infer function builder from a protocol requirement.
Allow a protocol requirement for a function or property to declare
a function builder. A witness to such a protocol requirement will
infer that function builder when all of the following are two:
* The witness does not explicitly adopt a function builder
* The witness is declared within the same context that conforms to the
protocol requirement (e.g., same extension or primary type declaration)
* The witness's body does not contain a "return" statement (since those
disable the function builder transform).
2020-05-24 23:18:18 -07:00
Slava Pestov
6303852c46 AST: Don't clone TypeReprs in ParamDecl::cloneWithoutType() 2020-05-23 02:23:43 -04:00
Slava Pestov
ae77d22893 AST: Don't clone TypeReprs in GenericParamList::clone() 2020-05-23 02:23:43 -04:00
Holly Borla
a97bbf9eee Merge pull request #31949 from hborla/property-wrapper-default-init
[Property Wrappers] Fix handling of properties that are default initialized via property wrapper
2020-05-21 18:01:42 -07:00
Holly Borla
1c8ad0024a [Property Wrappers] Fix ParamDecl::getDefaultValueStringRepresentation
to return a string representing default initialization when a
property is default initialized via property wrapper.
2020-05-21 14:21:50 -07:00
Suyash Srijan
d53cd535ba [Typechecker] Emit a specialised diagnostic for redeclaration errors when the declaration is synthesised (#31915)
* [Typechecker] Emit a specialized diagnostic for redeclaration errors when the declaration is synthesized

* [Test] Update existing tests

* [Typechecker] Diagnose the original wrapped property instead of the nearest non-implicit decl context

* [Test] Update existing tests

* [Typechecker] Do not diagnose redeclarations when both declarations are implicit

* [Test] Update a AutoDiff test
2020-05-21 17:37:55 +01:00
Michael Forster
e69abeba53 Classify C++ structs as loadable or address-only (#31707)
* Classify C++ structs as loadable or address-only

C++ structs are only loadable if they are trivially copyable.

Resolves SR-12472.
2020-05-13 17:16:47 +02:00
Dan Zheng
a5bdbd9774 [AutoDiff] Fix derivative function configurations for accessors. (#31669)
For accessors: make `AbstractFunctionDecl::getDerivativeFunctionConfigurations`
resolve configurations from parent storage declaration `@differentiable`
attributes.

Fixes "no `@differentiable` attribute" non-differentiability error for accessors
whose parent storage declaration `@differentiable` attributes have not been
type-checked (e.g. because the storage declarations are in another file).

Add protocol requirement and class member storage declaration tests.

Resolves TF-1234.
2020-05-09 07:29:15 -07:00
Alexis Laferrière
f46542f0e4 Merge pull request #31591 from xymus/spi-equatable
Allow SPI access within the same module in checkAccess
2020-05-08 11:29:12 -07:00
Saleem Abdulrasool
09975d1253 sprinkle llvm_unreachable for covered switches (NFC)
Annotate the covered switches with `llvm_unreachable` to avoid the MSVC
warning which does not recognise the covered switches.  This allows us
to avoid a spew of warnings.
2020-05-07 11:05:35 -07:00
Alexis Laferrière
4fcebd1256 Allow SPI access within the same module in checkAccess
rdar://problem/61043406
rdar://problem/61987739
2020-05-06 11:19:44 -07:00
Dan Zheng
738ef730e8 [AutoDiff] Fix @differentiable attribute derivative configurations. (#31524)
In `AbstractFunctionDecl::getDerivativeFunctionConfigurations`, type-check
`@differentiable` attributes. This is important to populate derivative
configurations for original functions in other files.

Resolves TF-1271.

Exposes TF-1272: fix derivative configurations for cross-file `@derivative`
attributes. This is a more difficult issue.
2020-05-04 00:44:48 -07:00
Varun Gandhi
65577940d0 [NFC] Get rid of -Wrange-loop-analysis warnings. (#31324) 2020-04-27 09:47:52 -07:00
Joe Groff
b4c7a7e85d Merge pull request #31224 from AnthonyLatsis/rename-getfullname-2
AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl
2020-04-24 12:51:28 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Slava Pestov
ec465e1616 Merge pull request #31212 from slavapestov/direct-to-storage-cleanup
Sema: Merge shouldAccessStorageDirectly() into isDirectToStorageAccess()
2020-04-22 22:03:55 -04:00
Slava Pestov
96b06784cf Sema: Merge shouldAccessStorageDirectly() into isDirectToStorageAccess() 2020-04-22 17:15:13 -04:00
Nate Chandler
81dc64fee3 @main: Enable main function to throw.
SE-0281 was accepted with the modification that the main function should
be allowed to be throwing.  Here support for enabling that is added.

Support is implemented in two steps:

(1) The $main wrapper function is modified to be throwing

static func $main() throws {
  return try main()
}

whenever the main function is throwing (it remains non-throwing when
$main is not throwing).

(2) The @main entry point is modified to be

sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
entry(%argc : $Int32, %argv : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
  %the_main_type = metatype $@thin TheMainType.Type
  %the_main_func = function_ref @`TheMainType.main()` : $@convention(method) (@thin TheMainType.Type) -> @error Error
  try_apply %the_main_func(%the_main_type) : $@convention(method) (@thin TheMainType.Type) -> @error Error, normal success, error failure

success(%_ : $()):
  %success_code_builtin_int32 = integer_literal $Builtin.Int32, 0
  br bb1(%success_code_builtin_int32 : $Builtin.Int32)

failure(%error : @owned $Error):
  %_ = builtin "errorInMain"(%error : $Error) : $()
  end_lifetime %error : $Error
  %error_code_builtin_int32 = integer_literal $Builtin.Int32, 1
  br bb1(%error_code_builtin_int32 : $Builtin.Int32)

exit(%code_builtin_int32 : $Builtin.Int32):
  %code = struct $Int32 (%code_builtin_int32 : $Builtin.Int32)
  return %code : $Int32
}

whenever the main function is throwing (and consequently $main also is).

In the non-throwing case, (a) the try_apply instruction is replaced with an
apply instruction, (b) the body of the success block is appended to the
entry block, and (c) the success and failure blocks are removed.
2020-04-17 11:33:31 -07:00
Nate Chandler
df99de804d Added executable entry-point via @main type.
When a type (class, enum, or struct) is annotated @main, it is required
to provide a function with the following signature:

  static func main() -> ()

That function will be called when the executable the type is defined
within is launched.
2020-04-17 09:53:46 -07:00
Xi Ge
c1e1cbad85 AST: teach getOpaqueResultTypeDecl() to get result for serialized AST
TBD was missing several opaque type descriptor symbols. The root causes
are: (1) the AST API called by TBD doesn't return opaque type decl if
the decl is from a serialized AST; and (2) the access level of opaque
type decl isn't serialized so TBD considers them as internal.

This change fixes both.

rdar://61833970
2020-04-16 22:16:23 -07:00
Holly Borla
66e85721cb Merge pull request #30807 from hborla/property-wrapper-refactoring
[Property Wrappers] Refactor property wrappers so the synthesized backing init is only type checked once
2020-04-14 10:48:22 -07:00
Slava Pestov
41ccedc999 AST: Fix opaque type mangling used by type reconstruction
Make sure we mangle opaque types using the same settings as the
debugger mangling (with OptimizeProtocolNames = false) to ensure
that we can reconstruct those names again.
2020-04-10 15:05:54 -04:00
Holly Borla
65105f3a26 [Property Wrappers] Introduce a new Expr node for the property wrapper
wrapped value placeholder in an init(wrappedValue:) call that was previously
injected as an OpaqueValueExpr. This commit also restores the old design of
OpaqueValueExpr.
2020-04-09 16:00:57 -07:00
Suyash Srijan
724f8c23db [Typechecker] Implement SE-0268 Refine didSet Semantics (#26632) 2020-04-09 01:23:15 +01:00
Dan Zheng
c834696bfa Add SynthesizedFileUnit.
`SynthesizedFileUnit` is a container for synthesized declarations. Currently, it
only supports module-level declarations.

It is used by the SIL differentiation transform, which generates implicit struct
and enum declarations.
2020-04-07 18:29:26 -07:00
Holly Borla
bbfcb55e9e [Property Wrappers] Inject the opaque value placeholder for a property
wrapper original wrapped value expression inside of CSApply.

This prevents type checking the synthesized backing storage initializer
twice - once with the original expression and again with the placeholder.
2020-04-05 19:02:37 -07:00