Skip to content

Commit 152ac7f

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents 643d81f + 413eba8 commit 152ac7f

File tree

7 files changed

+83
-10
lines changed

7 files changed

+83
-10
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3725,8 +3725,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
37253725
llvm::SaveAndRestore<bool> ChangeNeedOptionalUnwrap(NeedOptionalUnwrap,
37263726
true);
37273727
if (DotLoc.isValid()) {
3728+
// Let's not erase the dot if the completion is after a swift key path
3729+
// root because \A?.?.member is the correct way to access wrapped type
3730+
// member from an optional key path root.
3731+
auto loc = IsAfterSwiftKeyPathRoot ? DotLoc.getAdvancedLoc(1) : DotLoc;
37283732
NumBytesToEraseForOptionalUnwrap = Ctx.SourceMgr.getByteDistance(
3729-
DotLoc, Ctx.SourceMgr.getCodeCompletionLoc());
3733+
loc, Ctx.SourceMgr.getCodeCompletionLoc());
37303734
} else {
37313735
NumBytesToEraseForOptionalUnwrap = 0;
37323736
}
@@ -5934,7 +5938,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
59345938
if (!OnRoot && KPE->getComponents().back().getKind() ==
59355939
KeyPathExpr::Component::Kind::OptionalWrap) {
59365940
// KeyPath expr with '?' (e.g. '\Ty.[0].prop?.another').
5937-
// Althogh expected type is optional, we should unwrap it because it's
5941+
// Although expected type is optional, we should unwrap it because it's
59385942
// unwrapped.
59395943
baseType = baseType->getOptionalObjectType();
59405944
}

lib/Serialization/DeserializeSIL.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,14 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
511511
GenericSignatureID genericSigID;
512512
unsigned rawLinkage, isTransparent, isSerialized, isThunk,
513513
isWithoutactuallyEscapingThunk, specialPurpose, inlineStrategy,
514-
optimizationMode, subclassScope, effect, numSpecAttrs,
514+
optimizationMode, subclassScope, hasCReferences, effect, numSpecAttrs,
515515
hasQualifiedOwnership, isWeakImported, LIST_VER_TUPLE_PIECES(available),
516516
isDynamic, isExactSelfClass;
517517
ArrayRef<uint64_t> SemanticsIDs;
518518
SILFunctionLayout::readRecord(
519519
scratch, rawLinkage, isTransparent, isSerialized, isThunk,
520520
isWithoutactuallyEscapingThunk, specialPurpose, inlineStrategy,
521-
optimizationMode, subclassScope, effect, numSpecAttrs,
521+
optimizationMode, subclassScope, hasCReferences, effect, numSpecAttrs,
522522
hasQualifiedOwnership, isWeakImported, LIST_VER_TUPLE_PIECES(available),
523523
isDynamic, isExactSelfClass, funcTyID, replacedFunctionID, genericSigID,
524524
clangNodeOwnerID, SemanticsIDs);
@@ -639,6 +639,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
639639
fn->setOptimizationMode(OptimizationMode(optimizationMode));
640640
fn->setAlwaysWeakImported(isWeakImported);
641641
fn->setClassSubclassScope(SubclassScope(subclassScope));
642+
fn->setHasCReferences(bool(hasCReferences));
642643

643644
llvm::VersionTuple available;
644645
DECODE_VER_TUPLE(available);
@@ -2824,14 +2825,14 @@ bool SILDeserializer::hasSILFunction(StringRef Name,
28242825
GenericSignatureID genericSigID;
28252826
unsigned rawLinkage, isTransparent, isSerialized, isThunk,
28262827
isWithoutactuallyEscapingThunk, isGlobal, inlineStrategy,
2827-
optimizationMode, subclassScope, effect, numSpecAttrs,
2828+
optimizationMode, subclassScope, hasCReferences, effect, numSpecAttrs,
28282829
hasQualifiedOwnership, isWeakImported, LIST_VER_TUPLE_PIECES(available),
28292830
isDynamic, isExactSelfClass;
28302831
ArrayRef<uint64_t> SemanticsIDs;
28312832
SILFunctionLayout::readRecord(
28322833
scratch, rawLinkage, isTransparent, isSerialized, isThunk,
28332834
isWithoutactuallyEscapingThunk, isGlobal, inlineStrategy,
2834-
optimizationMode, subclassScope, effect, numSpecAttrs,
2835+
optimizationMode, subclassScope, hasCReferences, effect, numSpecAttrs,
28352836
hasQualifiedOwnership, isWeakImported, LIST_VER_TUPLE_PIECES(available),
28362837
isDynamic, isExactSelfClass, funcTyID, replacedFunctionID, genericSigID,
28372838
clangOwnerID, SemanticsIDs);

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
5757
/// Don't worry about adhering to the 80-column limit for this line.
58-
const uint16_t SWIFTMODULE_VERSION_MINOR = 575; // GlobalInitOnceFunction SILFunction purpose
58+
const uint16_t SWIFTMODULE_VERSION_MINOR = 576; // hasCReferences
5959

6060
/// A standard hash seed used for all string hashes in a serialized module.
6161
///

lib/Serialization/SILFormat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ namespace sil_block {
281281
BCFixed<2>, // inlineStrategy
282282
BCFixed<2>, // optimizationMode
283283
BCFixed<2>, // classSubclassScope
284+
BCFixed<1>, // hasCReferences
284285
BCFixed<3>, // side effect info.
285286
BCVBR<8>, // number of specialize attributes
286287
BCFixed<1>, // has qualified ownership

lib/Serialization/SerializeSIL.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,9 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
433433
Out, ScratchRecord, abbrCode, toStableSILLinkage(Linkage),
434434
(unsigned)F.isTransparent(), (unsigned)F.isSerialized(),
435435
(unsigned)F.isThunk(), (unsigned)F.isWithoutActuallyEscapingThunk(),
436-
(unsigned)F.getSpecialPurpose(),
437-
(unsigned)F.getInlineStrategy(), (unsigned)F.getOptimizationMode(),
438-
(unsigned)F.getClassSubclassScope(), (unsigned)F.getEffectsKind(),
436+
(unsigned)F.getSpecialPurpose(), (unsigned)F.getInlineStrategy(),
437+
(unsigned)F.getOptimizationMode(), (unsigned)F.getClassSubclassScope(),
438+
(unsigned)F.hasCReferences(), (unsigned)F.getEffectsKind(),
439439
(unsigned)numSpecAttrs, (unsigned)F.hasOwnership(),
440440
F.isAlwaysWeakImported(), LIST_VER_TUPLE_PIECES(available),
441441
(unsigned)F.isDynamicallyReplaceable(), (unsigned)F.isExactSelfClass(),
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TYPE_INFER_DOT_OPTIONAL | %FileCheck %s -check-prefix=PERSONTYPE-INFER-DOT-OPT
2+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TYPE_DOT_OPTIONAL | %FileCheck %s -check-prefix=PERSONTYPE-DOT-OPT
3+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TYPE_DOT_OPTIONAL_SPACE | %FileCheck %s -check-prefix=PERSONTYPE-DOT-OPT-SPACE
4+
5+
class Person {
6+
var name: String
7+
var friends: [Person] = []
8+
var bestFriend: Person? = nil
9+
var itself: Person { return self }
10+
init(name: String) {
11+
self.name = name
12+
}
13+
func getName() -> String { return name }
14+
subscript(_ index: Int) -> Int { get { return 1} }
15+
}
16+
17+
extension Optional {
18+
var optMember: String { "member" }
19+
}
20+
21+
let _ : KeyPath<Person?, String> = \.#^TYPE_INFER_DOT_OPTIONAL^#
22+
// PERSONTYPE-INFER-DOT-OPT: Begin completions, 9 items
23+
// PERSONTYPE-INFER-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal: ?.name[#String#]; name=name
24+
// PERSONTYPE-INFER-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal: ?.friends[#[Person]#]; name=friends
25+
// PERSONTYPE-INFER-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal: ?.bestFriend[#Person?#]; name=bestFriend
26+
// PERSONTYPE-INFER-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal: ?.itself[#Person#]; name=itself
27+
// PERSONTYPE-INFER-DOT-OPT-NEXT: Decl[Subscript]/CurrNominal: ?[{#(index): Int#}][#Int#]; name=[index: Int]
28+
// PERSONTYPE-INFER-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal/IsSystem: unsafelyUnwrapped[#Person#]; name=unsafelyUnwrapped
29+
// PERSONTYPE-INFER-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal: optMember[#String#]; name=optMember
30+
// PERSONTYPE-INFER-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal/IsSystem: debugDescription[#String#]; name=debugDescription
31+
// PERSONTYPE-INFER-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal/IsSystem: customMirror[#Mirror#]; name=customMirror
32+
33+
let _ : KeyPath<Person?, String> = \Person?.#^TYPE_DOT_OPTIONAL^#
34+
// PERSONTYPE-DOT-OPT: Begin completions, 9 items
35+
// PERSONTYPE-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal: ?.name[#String#]; name=name
36+
// PERSONTYPE-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal: ?.friends[#[Person]#]; name=friends
37+
// PERSONTYPE-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal: ?.bestFriend[#Person?#]; name=bestFriend
38+
// PERSONTYPE-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal: ?.itself[#Person#]; name=itself
39+
// PERSONTYPE-DOT-OPT-NEXT: Decl[Subscript]/CurrNominal: ?[{#(index): Int#}][#Int#]; name=[index: Int]
40+
// PERSONTYPE-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal/IsSystem: unsafelyUnwrapped[#Person#]; name=unsafelyUnwrapped
41+
// PERSONTYPE-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal: optMember[#String#]; name=optMember
42+
// PERSONTYPE-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal/IsSystem: debugDescription[#String#]; name=debugDescription
43+
// PERSONTYPE-DOT-OPT-NEXT: Decl[InstanceVar]/CurrNominal/IsSystem: customMirror[#Mirror#]; name=customMirror
44+
45+
let _ : KeyPath<Person?, String> = \Person?. #^TYPE_DOT_OPTIONAL_SPACE^#
46+
// PERSONTYPE-DOT-OPT-SPACE: Begin completions, 9 items
47+
// PERSONTYPE-DOT-OPT-SPACE-NEXT: Decl[InstanceVar]/CurrNominal/Erase[1]: ?.name[#String#]; name=name
48+
// PERSONTYPE-DOT-OPT-SPACE-NEXT: Decl[InstanceVar]/CurrNominal/Erase[1]: ?.friends[#[Person]#]; name=friends
49+
// PERSONTYPE-DOT-OPT-SPACE-NEXT: Decl[InstanceVar]/CurrNominal/Erase[1]: ?.bestFriend[#Person?#]; name=bestFriend
50+
// PERSONTYPE-DOT-OPT-SPACE-NEXT: Decl[InstanceVar]/CurrNominal/Erase[1]: ?.itself[#Person#]; name=itself
51+
// PERSONTYPE-DOT-OPT-SPACE-NEXT: Decl[Subscript]/CurrNominal/Erase[1]: ?[{#(index): Int#}][#Int#]; name=[index: Int]
52+
// PERSONTYPE-DOT-OPT-SPACE-NEXT: Decl[InstanceVar]/CurrNominal/IsSystem: unsafelyUnwrapped[#Person#]; name=unsafelyUnwrapped
53+
// PERSONTYPE-DOT-OPT-SPACE-NEXT: Decl[InstanceVar]/CurrNominal: optMember[#String#]; name=optMember
54+
// PERSONTYPE-DOT-OPT-SPACE-NEXT: Decl[InstanceVar]/CurrNominal/IsSystem: debugDescription[#String#]; name=debugDescription
55+
// PERSONTYPE-DOT-OPT-SPACE-NEXT: Decl[InstanceVar]/CurrNominal/IsSystem: customMirror[#Mirror#]; name=customMirror

test/Serialization/cdecl_attr.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %empty-directory(%t)
2+
// Ensure .swift -> .ll
3+
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
4+
5+
// Ensure .swift -> .sib -> .ll
6+
// RUN: %target-swift-frontend -emit-sib %s -o %t/cdecl_attr.sib
7+
// RUN: %target-swift-frontend -emit-ir %t/cdecl_attr.sib | %FileCheck %s
8+
9+
// CHECK: define hidden {{.*}} @foo
10+
11+
@_cdecl("foo")
12+
func foo() {}

0 commit comments

Comments
 (0)