Skip to content

Commit 63c3f1f

Browse files
committed
Revert "Merge pull request #81840 from compnerd/aliases"
This reverts commit 33a324e, reversing changes made to 0afeafa due to a regression: ``` $ printf "import var Darwin.stderr\n" | /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-06-09-a.xctoolchain/usr/bin/swiftc -typecheck - -sdk $(xcrun --show-sdk-path) <stdin>:1:12: error: ambiguous name 'stderr' in module 'Darwin' 1 | import var Darwin.stderr | `- error: ambiguous name 'stderr' in module 'Darwin' 2 | _stdio.stderr:2:12: note: found this candidate 1 | @available(macOS 10.9, iOS 7.0, watchOS 2.0, tvOS 9.0, visionOS 1.0, *) 2 | public var stderr: UnsafeMutablePointer<FILE> { get set } | `- note: found this candidate _stdio.stderr:1:12: note: found this candidate 1 | public var stderr: UnsafeMutablePointer<FILE> { get set } | `- note: found this candidate ``` # Conflicts: # test/ClangImporter/Inputs/custom-modules/module.modulemap
1 parent c24bae7 commit 63c3f1f

File tree

6 files changed

+3
-249
lines changed

6 files changed

+3
-249
lines changed

lib/ClangImporter/ImportMacro.cpp

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "swift/AST/ASTContext.h"
2121
#include "swift/AST/DiagnosticsClangImporter.h"
2222
#include "swift/AST/Expr.h"
23-
#include "swift/AST/ParameterList.h"
2423
#include "swift/AST/Stmt.h"
2524
#include "swift/AST/Types.h"
2625
#include "swift/Basic/Assertions.h"
@@ -32,7 +31,6 @@
3231
#include "clang/Lex/MacroInfo.h"
3332
#include "clang/Lex/Preprocessor.h"
3433
#include "clang/Sema/DelayedDiagnostic.h"
35-
#include "clang/Sema/Lookup.h"
3634
#include "clang/Sema/Sema.h"
3735
#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
3836
#include "llvm/ADT/SmallString.h"
@@ -373,104 +371,6 @@ getIntegerConstantForMacroToken(ClangImporter::Implementation &impl,
373371
return std::nullopt;
374372
}
375373

376-
namespace {
377-
ValueDecl *importDeclAlias(ClangImporter::Implementation &clang,
378-
swift::DeclContext *DC, const clang::ValueDecl *D,
379-
Identifier alias) {
380-
// Variadic functions cannot be imported into Swift.
381-
// FIXME(compnerd) emit a diagnostic for the missing diagnostic.
382-
if (const auto *FD = dyn_cast<clang::FunctionDecl>(D))
383-
if (FD->isVariadic())
384-
return nullptr;
385-
386-
// Ignore self-referential macros.
387-
if (D->getName() == alias.str())
388-
return nullptr;
389-
390-
swift::ValueDecl *VD =
391-
dyn_cast_or_null<ValueDecl>(clang.importDecl(D, clang.CurrentVersion));
392-
if (VD == nullptr)
393-
return nullptr;
394-
395-
// If the imported decl is named identically, avoid the aliasing.
396-
if (VD->getBaseIdentifier().str() == alias.str())
397-
return nullptr;
398-
399-
swift::ASTContext &Ctx = DC->getASTContext();
400-
ImportedType Ty =
401-
clang.importType(D->getType(), ImportTypeKind::Abstract,
402-
[&clang, &D](Diagnostic &&Diag) {
403-
clang.addImportDiagnostic(D, std::move(Diag),
404-
D->getLocation());
405-
}, /*AllowsNSUIntegerAsInt*/true,
406-
Bridgeability::None, { });
407-
swift::Type GetterTy = FunctionType::get({}, Ty.getType(), ASTExtInfo{});
408-
swift::Type SetterTy =
409-
FunctionType::get({AnyFunctionType::Param(Ty.getType())},
410-
Ctx.TheEmptyTupleType, ASTExtInfo{});
411-
412-
/* Storage */
413-
swift::VarDecl *V =
414-
new (Ctx) VarDecl(/*IsStatic*/false, VarDecl::Introducer::Var,
415-
SourceLoc(), alias, DC);
416-
V->setAccess(swift::AccessLevel::Public);
417-
V->setInterfaceType(Ty.getType());
418-
V->getAttrs().add(new (Ctx) TransparentAttr(/*Implicit*/true));
419-
V->getAttrs().add(new (Ctx) InlineAttr(InlineKind::Always));
420-
421-
/* Accessor */
422-
swift::AccessorDecl *G = nullptr;
423-
{
424-
G = AccessorDecl::createImplicit(Ctx, AccessorKind::Get, V, false, false,
425-
TypeLoc(), GetterTy, DC);
426-
G->setAccess(swift::AccessLevel::Public);
427-
G->setInterfaceType(GetterTy);
428-
G->setIsTransparent(true);
429-
G->setParameters(ParameterList::createEmpty(Ctx));
430-
431-
DeclRefExpr *DRE =
432-
new (Ctx) DeclRefExpr(ConcreteDeclRef(VD), {}, /*Implicit*/true,
433-
AccessSemantics::Ordinary, Ty.getType());
434-
ReturnStmt *RS = ReturnStmt::createImplicit(Ctx, DRE);
435-
436-
G->setBody(BraceStmt::createImplicit(Ctx, {RS}),
437-
AbstractFunctionDecl::BodyKind::TypeChecked);
438-
}
439-
440-
swift::AccessorDecl *S = nullptr;
441-
if (isa<clang::VarDecl>(D) &&
442-
!cast<clang::VarDecl>(D)->getType().isConstQualified()) {
443-
S = AccessorDecl::createImplicit(Ctx, AccessorKind::Set, V, false, false,
444-
TypeLoc(), Ctx.TheEmptyTupleType, DC);
445-
S->setAccess(swift::AccessLevel::Public);
446-
S->setInterfaceType(SetterTy);
447-
S->setIsTransparent(true);
448-
S->setParameters(ParameterList::create(Ctx, {
449-
ParamDecl::createImplicit(Ctx, Identifier(), Ctx.getIdentifier("newValue"),
450-
Ty.getType(), DC)
451-
}));
452-
453-
DeclRefExpr *LHS =
454-
new (Ctx) DeclRefExpr(ConcreteDeclRef(VD), {}, /*Implicit*/true,
455-
AccessSemantics::Ordinary, Ty.getType());
456-
DeclRefExpr *RHS =
457-
new (Ctx) DeclRefExpr(S->getParameters()->get(0), {}, /*Implicit*/true,
458-
AccessSemantics::Ordinary, Ty.getType());
459-
AssignExpr *AE = new (Ctx) AssignExpr(LHS, SourceLoc(), RHS, true);
460-
AE->setType(Ctx.TheEmptyTupleType);
461-
S->setBody(BraceStmt::createImplicit(Ctx, {AE}),
462-
AbstractFunctionDecl::BodyKind::TypeChecked);
463-
}
464-
465-
/* Bind */
466-
V->setImplInfo(S ? StorageImplInfo::getMutableComputed()
467-
: StorageImplInfo::getImmutableComputed());
468-
V->setAccessors(SourceLoc(), S ? ArrayRef{G,S} : ArrayRef{G}, SourceLoc());
469-
470-
return V;
471-
}
472-
}
473-
474374
static ValueDecl *importMacro(ClangImporter::Implementation &impl,
475375
llvm::SmallSet<StringRef, 4> &visitedMacros,
476376
DeclContext *DC, Identifier name,
@@ -609,14 +509,7 @@ static ValueDecl *importMacro(ClangImporter::Implementation &impl,
609509
}
610510
}
611511

612-
/* Create an alias for any Decl */
613-
clang::Sema &S = impl.getClangSema();
614-
clang::LookupResult R(S, {{tok.getIdentifierInfo()}, {}},
615-
clang::Sema::LookupAnyName);
616-
if (S.LookupName(R, S.TUScope))
617-
if (R.getResultKind() == clang::LookupResult::LookupResultKind::Found)
618-
if (const auto *VD = dyn_cast<clang::ValueDecl>(R.getFoundDecl()))
619-
return importDeclAlias(impl, DC, VD, name);
512+
// FIXME: If the identifier refers to a declaration, alias it?
620513
}
621514

622515
// TODO(https://github.com/apple/swift/issues/57735): Seems rare to have a single token that is neither a literal nor an identifier, but add diagnosis.

test/ClangImporter/CoreGraphics_test.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ public func testRenames(transform: CGAffineTransform, context: CGContext,
105105
blackHole(point.applying(transform))
106106
var rect = rect.applying(transform)
107107
blackHole(size.applying(transform))
108+
// CHECK: %{{.*}} = {{(tail )?}}call { double, double } @CGPointApplyAffineTransform(double %{{.*}}, double %{{.*}}, ptr {{.*}})
108109
// CHECK: call void @CGRectApplyAffineTransform(ptr {{.*}}, ptr {{.*}}, ptr {{.*}})
110+
// CHECK: %{{.*}} = {{(tail )?}}call { double, double } @CGSizeApplyAffineTransform(double %{{.*}}, double %{{.*}}, ptr {{.*}})
109111

110112
context.concatenate(transform)
111113
context.rotate(by: CGFloat.pi)

test/ClangImporter/Inputs/custom-modules/Aliases.h

Lines changed: 0 additions & 53 deletions
This file was deleted.

test/ClangImporter/Inputs/custom-modules/module.modulemap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,6 @@ module "Weird C Module" {
276276
header "WeirdCModule.h"
277277
}
278278

279-
module Aliases {
280-
header "Aliases.h"
281-
}
282-
283279
module RetroactiveVersioning {
284280
header "versioning.h"
285281
}

test/ClangImporter/alias-invalid.swift

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/ClangImporter/alias.swift

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)