Skip to content

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Sep 11, 2025

Allow unsafe pointer to access a ~Escapable Pointee.

This is a placeholder for review and to drive implementation of compiler Builtins. I suspect @lorentey will ultimately have a PR with the standard library additions.

@atrick atrick requested a review from a team as a code owner September 11, 2025 17:35
@atrick atrick marked this pull request as draft September 11, 2025 17:36
@atrick atrick requested a review from lorentey September 11, 2025 17:37
@atrick atrick force-pushed the unsafe-pointer-nonescapable branch from 7bc91c5 to 9d0a464 Compare September 18, 2025 00:12
@atrick
Copy link
Contributor Author

atrick commented Sep 18, 2025

@lorentey I'm using this PR to test compiler fixes. I think it's almost there and will land the few small compiler commits ASAP.

The hard problem: safely migrating all the signatures and symbols remains. In particular:


Backward compatibility with deprecated APIs:

test/Generics/slice_test.swift
test/Parse/pointer_conversion.swift.gyb
test/SILGen/borrow_from_load_expr.swift

error: unexpected warning produced: 'initialize(to:count:)' is deprecated: renamed to 'initialize(repeating:count:)'

Problem: -swift-version 4 does not appear to resolve calls to the new form of initialize(to:).


Mangled names

test/SILGen/borrow_from_load_expr.swift

UnsafeMutablePointer.subscript.unsafeAddressor name mangling changes


Documenting Escapable requirements

test/SourceKit/DocSupport/doc_clang_module.swift

Need to add Escapable as a conformance:

@@ -6203,6 +6203,11 @@
         key.kind: source.lang.swift.ref.protocol,
         key.name: "Copyable",
         key.usr: "s:s8CopyableP"
+      },
+      {
+        key.kind: source.lang.swift.ref.protocol,
+        key.name: "Escapable",
+        key.usr: "s:s9EscapableP"
       }

API signature changes

test/api-digester/stability-stdlib-source.swift

Accessor UnsafeMutablePointer.hashValue.Get() has generic signature change from to <Pointee where Pointee : ~Copyable, Pointee : ~Escapable>
etc...

@atrick
Copy link
Contributor Author

atrick commented Sep 18, 2025

@swift-ci test

1 similar comment
@atrick
Copy link
Contributor Author

atrick commented Sep 18, 2025

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Sep 18, 2025

@swift-ci benchmark

@atrick
Copy link
Contributor Author

atrick commented Sep 18, 2025

@swift-ci Please Build Toolchain macOS Platform

atrick added 14 commits October 6, 2025 10:54
loadUnaligned only supports loading non-BitwiseCopyable values. The generic
loadUnaligned should also be supported but it depends on UnsafePointer<T:
~Escapable>.
Only supports non-BitwiseCopyable values. The generic storeBytes should also be
supported but it depends on UnsafePointer<T: ~Escapable>.
Handle storing to a mutable property implemented as unsafeMutableAddress. In
SIL, the stored address comes from pointer_to_address. Recognize the addressor
pattern and handle the store as if it writes to a regular property of 'self'.

Required for UnsafePointer<~Escapable>.pointee.
New declaration:
Unsafe[Mutable]Pointer<Pointee: ~Copyable & ~Escapable>
@atrick atrick force-pushed the unsafe-pointer-nonescapable branch from 9d0a464 to 78c608b Compare October 6, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant