Skip to content

Commit d44d972

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 29741f7 + 9c584d8 commit d44d972

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1212
-482
lines changed

docs/CppInteroperability/GettingStartedWithC++Interop.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ module CxxTest {
3232
Add the C++ module to the include path and enable C++ interop:
3333
- Navigate to your project directory
3434
- In `Project` navigate to `Build Settings` -> `Swift Compiler`
35-
- Under `Custom Flags` -> `Other Swift Flags` add`-enable-experimental-cxx-interop`
36-
- Under `Search Paths` -> `Import Paths` add your search path to the C++ module (i.e, `./ProjectName/CxxTest`). Repeat this step in `Other Swift Flags`
35+
- Under `Custom Flags` -> `Other Swift Flags` add `-Xfrontend -enable-experimental-cxx-interop`
36+
- Under `Search Paths` -> `Import Paths` add your search path to the C++ module (i.e, `./ProjectName/CxxTest`).
3737

3838
```
39-
//Add to Other Swift Flags and Import Paths respectively
40-
-enable-experimental-cxx-interop
39+
// Add to Other Swift Flags and Import Paths respectively
40+
-Xfrontend -enable-experimental-cxx-interop
4141
-I./ProjectName/CxxTest
4242
```
4343

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===--- MockPlugin.h ---------------------------------------------*- C -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_C_MOCK_PLUGIN_H
14+
#define SWIFT_C_MOCK_PLUGIN_H
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
int _mock_plugin_main(const char *);
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
26+
/// Usage: MOCK_PLUGIN(JSON)
27+
/// 'JSON' is a *bare* JSON value.
28+
#define MOCK_PLUGIN(...) \
29+
int main() { return _mock_plugin_main(#__VA_ARGS__); }
30+
31+
#endif // SWIFT_C_MOCK_PLUGIN_H

include/swift/AST/CASTBridging.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,18 @@ extern "C" {
118118
/// information and then must be finished via \c SwiftDiagnostic_finish.
119119
BridgedDiagnostic SwiftDiagnostic_create(
120120
void *diagnosticEngine, BridgedDiagnosticSeverity severity,
121-
void *_Nullable sourceLoc,
121+
const void *_Nullable sourceLoc,
122122
const uint8_t *_Nullable text, long textLen);
123123

124124
/// Highlight a source range as part of the diagnostic.
125125
void SwiftDiagnostic_highlight(
126-
BridgedDiagnostic diag, void *_Nullable startLoc, void *_Nullable endLoc);
126+
BridgedDiagnostic diag, const void *_Nullable startLoc, const void *_Nullable endLoc);
127127

128128
/// Add a Fix-It to replace a source range as part of the diagnostic.
129129
void SwiftDiagnostic_fixItReplace(
130130
BridgedDiagnostic diag,
131-
void *_Nullable replaceStartLoc, void *_Nullable replaceEndLoc,
131+
const void *_Nullable replaceStartLoc,
132+
const void *_Nullable replaceEndLoc,
132133
const uint8_t *_Nullable newText, long newTextLen);
133134

134135
/// Finish the given diagnostic and emit it.

include/swift/AST/Decl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,12 @@ class ImportDecl final : public Decl,
14231423
/// the decls it references. Otherwise, returns an empty array.
14241424
ArrayRef<ValueDecl *> getDecls() const;
14251425

1426+
/// Access level of this import, either explicitly declared or implicit.
1427+
AccessLevel getAccessLevel() const;
1428+
1429+
/// Is the access level of this import implicit, aka a default import?
1430+
bool isAccessLevelImplicit() const;
1431+
14261432
const clang::Module *getClangModule() const {
14271433
return getClangNode().getClangModule();
14281434
}

include/swift/AST/DiagnosticEngine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace swift {
4141
class Decl;
4242
class DeclAttribute;
4343
class DiagnosticEngine;
44+
class GeneratedSourceInfo;
4445
class SourceManager;
4546
class ValueDecl;
4647
class SourceFile;
@@ -1478,6 +1479,10 @@ namespace swift {
14781479
std::pair<unsigned, DeclName>
14791480
getAccessorKindAndNameForDiagnostics(const ValueDecl *D);
14801481

1482+
/// Retrieve the macro name for a generated source info that represents
1483+
/// a macro expansion.
1484+
DeclName getGeneratedSourceInfoMacroName(const GeneratedSourceInfo &info);
1485+
14811486
} // end namespace swift
14821487

14831488
#endif

include/swift/AST/DiagnosticsSema.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,6 +2048,16 @@ ERROR(spi_only_imports_not_enabled, none,
20482048
"'@_spiOnly' requires setting the frontend flag '-experimental-spi-only-imports'",
20492049
())
20502050

2051+
// Access level on imports
2052+
ERROR(access_level_on_import_not_enabled, none,
2053+
"Access level on imports require '-enable-experimental-feature AccessLevelOnImport'",
2054+
())
2055+
ERROR(access_level_on_import_unsupported, none,
2056+
"The access level %0 is unsupported on imports: "
2057+
"only 'public', 'package', 'internal', 'fileprivate' and 'private' "
2058+
"are unsupported",
2059+
(DeclAttribute))
2060+
20512061
// Opaque return types
20522062
ERROR(opaque_type_invalid_constraint,none,
20532063
"an 'opaque' type must specify only 'Any', 'AnyObject', protocols, "

include/swift/AST/Import.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -584,14 +584,24 @@ struct AttributedImport {
584584
/// attribute, this is the given access level.
585585
Optional<AccessLevel> docVisibility;
586586

587+
/// Access level limiting how imported types can be exported.
588+
AccessLevel accessLevel;
589+
590+
/// Location of the attribute that defined \c accessLevel. Also indicates
591+
/// if the access level was implicit or explicit.
592+
SourceLoc accessLevelLoc;
593+
587594
AttributedImport(ModuleInfo module, SourceLoc importLoc = SourceLoc(),
588595
ImportOptions options = ImportOptions(),
589596
StringRef filename = {}, ArrayRef<Identifier> spiGroups = {},
590597
SourceRange preconcurrencyRange = {},
591-
Optional<AccessLevel> docVisibility = None)
598+
Optional<AccessLevel> docVisibility = None,
599+
AccessLevel accessLevel = AccessLevel::Public,
600+
SourceLoc accessLevelLoc = SourceLoc())
592601
: module(module), importLoc(importLoc), options(options),
593602
sourceFileArg(filename), spiGroups(spiGroups),
594-
preconcurrencyRange(preconcurrencyRange), docVisibility(docVisibility) {
603+
preconcurrencyRange(preconcurrencyRange), docVisibility(docVisibility),
604+
accessLevel(accessLevel), accessLevelLoc(accessLevelLoc) {
595605
assert(!(options.contains(ImportFlags::Exported) &&
596606
options.contains(ImportFlags::ImplementationOnly)) ||
597607
options.contains(ImportFlags::Reserved));
@@ -601,15 +611,18 @@ struct AttributedImport {
601611
AttributedImport(ModuleInfo module, AttributedImport<OtherModuleInfo> other)
602612
: AttributedImport(module, other.importLoc, other.options,
603613
other.sourceFileArg, other.spiGroups,
604-
other.preconcurrencyRange, other.docVisibility) { }
614+
other.preconcurrencyRange, other.docVisibility,
615+
other.accessLevel, other.accessLevelLoc) { }
605616

606617
friend bool operator==(const AttributedImport<ModuleInfo> &lhs,
607618
const AttributedImport<ModuleInfo> &rhs) {
608619
return lhs.module == rhs.module &&
609620
lhs.options.toRaw() == rhs.options.toRaw() &&
610621
lhs.sourceFileArg == rhs.sourceFileArg &&
611622
lhs.spiGroups == rhs.spiGroups &&
612-
lhs.docVisibility == rhs.docVisibility;
623+
lhs.docVisibility == rhs.docVisibility &&
624+
lhs.accessLevel == rhs.accessLevel &&
625+
lhs.accessLevelLoc == rhs.accessLevelLoc;
613626
}
614627

615628
AttributedImport<ImportedModule> getLoaded(ModuleDecl *loadedModule) const {
@@ -761,14 +774,16 @@ struct DenseMapInfo<swift::AttributedImport<ModuleInfo>> {
761774
SourceLocDMI::getEmptyKey(),
762775
ImportOptionsDMI::getEmptyKey(),
763776
StringRefDMI::getEmptyKey(),
764-
{}, {}, None);
777+
{}, {}, None,
778+
swift::AccessLevel::Public, {});
765779
}
766780
static inline AttributedImport getTombstoneKey() {
767781
return AttributedImport(ModuleInfoDMI::getTombstoneKey(),
768782
SourceLocDMI::getEmptyKey(),
769783
ImportOptionsDMI::getTombstoneKey(),
770784
StringRefDMI::getTombstoneKey(),
771-
{}, {}, None);
785+
{}, {}, None,
786+
swift::AccessLevel::Public, {});
772787
}
773788
static inline unsigned getHashValue(const AttributedImport &import) {
774789
return detail::combineHashValue(
@@ -783,7 +798,9 @@ struct DenseMapInfo<swift::AttributedImport<ModuleInfo>> {
783798
ImportOptionsDMI::isEqual(a.options, b.options) &&
784799
StringRefDMI::isEqual(a.sourceFileArg, b.sourceFileArg) &&
785800
a.spiGroups == b.spiGroups &&
786-
a.docVisibility == b.docVisibility;
801+
a.docVisibility == b.docVisibility &&
802+
a.accessLevel == b.accessLevel &&
803+
a.accessLevelLoc == b.accessLevelLoc;
787804
}
788805
};
789806
}

include/swift/Basic/Features.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ EXPERIMENTAL_FEATURE(MoveOnlyClasses, true)
116116
EXPERIMENTAL_FEATURE(OneWayClosureParameters, false)
117117
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference, false)
118118
EXPERIMENTAL_FEATURE(LayoutPrespecialization, true)
119+
119120
EXPERIMENTAL_FEATURE(ModuleInterfaceExportAs, true)
121+
EXPERIMENTAL_FEATURE(AccessLevelOnImport, false)
120122

121123
/// Whether to enable experimental layout string value witnesses
122124
EXPERIMENTAL_FEATURE(LayoutStringValueWitnesses, true)

include/swift/Frontend/PrintingDiagnosticConsumer.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/Basic/DiagnosticOptions.h"
2323
#include "swift/Basic/LLVM.h"
2424

25+
#include "llvm/ADT/DenseMap.h"
2526
#include "llvm/Support/raw_ostream.h"
2627
#include "llvm/Support/Process.h"
2728

@@ -47,10 +48,14 @@ class PrintingDiagnosticConsumer : public DiagnosticConsumer {
4748
bool SuppressOutput = false;
4849

4950
/// swift-syntax rendering
51+
52+
/// A queued up source file known to the queued diagnostics.
53+
using QueuedBuffer = void *;
54+
55+
/// The queued diagnostics structure.
5056
void *queuedDiagnostics = nullptr;
51-
void *queuedSourceFile = nullptr;
52-
unsigned queuedDiagnosticsBufferID;
53-
StringRef queuedBufferName;
57+
llvm::DenseMap<unsigned, QueuedBuffer> queuedBuffers;
58+
unsigned queuedDiagnosticsOutermostBufferID;
5459

5560
public:
5661
PrintingDiagnosticConsumer(llvm::raw_ostream &stream = llvm::errs());
@@ -91,6 +96,7 @@ class PrintingDiagnosticConsumer : public DiagnosticConsumer {
9196
}
9297

9398
private:
99+
void queueBuffer(SourceManager &sourceMgr, unsigned bufferID);
94100
void printDiagnostic(SourceManager &SM, const DiagnosticInfo &Info);
95101
};
96102

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,6 +3118,10 @@ static bool usesFeatureModuleInterfaceExportAs(Decl *decl) {
31183118
return false;
31193119
}
31203120

3121+
static bool usesFeatureAccessLevelOnImport(Decl *decl) {
3122+
return false;
3123+
}
3124+
31213125
static bool usesFeatureNamedOpaqueTypes(Decl *decl) {
31223126
return false;
31233127
}

0 commit comments

Comments
 (0)