Skip to content

Commit

Permalink
Merge branch 'main' of github.com:hylo-lang/hylo into coercions
Browse files Browse the repository at this point in the history
  • Loading branch information
kyouko-taiga committed Sep 4, 2023
2 parents acef096 + a4422be commit 7bf524f
Show file tree
Hide file tree
Showing 106 changed files with 1,053 additions and 541 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ jobs:

runs-on: ${{ matrix.host.os }}
steps:
- uses: actions/checkout@v3

- uses: actions/cache@v3
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- uses: actions/checkout@v3

- run: git config --global core.autocrlf input

- name: Build and Test
uses: devcontainers/[email protected]
with:
Expand Down Expand Up @@ -108,8 +106,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- run: git config --global core.autocrlf input

- name: Setup swift
uses: swift-actions/setup-swift@v1
with:
Expand Down Expand Up @@ -148,7 +144,7 @@ jobs:
https://github.com/apple/swift-package-manager/issues/6595" && false) )
build-native-windows:
name: "Native: windows-latest/release"
name: "Native, no testing: windows-latest/release"
strategy:
fail-fast: false
runs-on: windows-latest
Expand All @@ -159,8 +155,6 @@ jobs:
branch: swift-5.8.1-release
tag: 5.8.1-RELEASE

- run: |
git config --global core.autocrlf input
- uses: actions/checkout@v3

- name: Swift version
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/doc-extraction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3

- uses: actions/cache@v3
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- uses: actions/checkout@v3
- run: git config --global core.autocrlf input

- name: Setup swift
uses: swift-actions/setup-swift@v1
with:
Expand Down Expand Up @@ -85,7 +84,7 @@ jobs:
export PKG_CONFIG_PATH
for TARGET in ${EXTRACTION_TARGETS}; do
mkdir -p _site/docc/"$TARGET"
swift package --allow-writing-to-directory ./_site \
Tools/retry-once swift package --allow-writing-to-directory ./_site \
generate-documentation \
--target "$TARGET" \
--output-path _site/docc/"${TARGET}" \
Expand Down Expand Up @@ -128,7 +127,7 @@ jobs:

- name: Fix permissions
run: |
chmod -v -R +rX "_site/" | while read line; do
chmod -v -R +rX "_site/" | while read -r line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done
Expand Down
28 changes: 10 additions & 18 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Format check

defaults:
run:
shell: bash -eo pipefail {0}

on:
push:
branches: [ main ]
Expand All @@ -21,27 +25,15 @@ on:
jobs:
build:
name: Format check
runs-on: ubuntu-latest
runs-on: macos-latest

steps:
- uses: actions/cache@v3
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- name: install swift-format
run: |
brew install swift-format
- name: Checkout
uses: actions/checkout@v3

- run: git config --global core.autocrlf input

- name: Setup swift
uses: swift-actions/setup-swift@v1
with:
swift-version: "5.8"

- name: Swift version
run: swift --version

- name: Check code format
run: Tools/run-swift-format.sh -d lint
run: swift-format lint -r --configuration .swift-format.json -p Sources Tests Package.swift
13 changes: 13 additions & 0 deletions .github/workflows/spell-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Spell check
on: [pull_request, push]

jobs:
run:
name: Spell Check using typos
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v3

- name: Check spelling of file.txt
uses: crate-ci/[email protected]
3 changes: 3 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[default.extend-words]
inout = "inout" # Mutable projection keyword
olt = "olt" # Abbreviation for "ordered less than"
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,17 @@ You will need to manually [synchronize it](https://docs.github.com/en/pull-reque
Make sure your changes do not break anything by running all existing tests.
We also ask that you write tests for the code you want to contribute.

Ensure your changes do not intruduce any spelling errors. We use [typos-action]
to ensure no mistakes creep in. To run locally, [install typos] and run `typos`
to run a check and `typos -w` to automatically apply suggestions. If you run
into any false positives see the [typos false positives documentation].

Before issuing a pull request we ask that you squash all your commits into a single logical commit that describes your contribution.
We may ask you to commit additional changes while your pull request is under review.
Once everything looks good, squash those additional commits before merging.

Do not hesitate to reach out if you are lost in the process.

[typos-action]: https://github.com/marketplace/actions/typos-action
[install typos]: https://github.com/crate-ci/typos#install
[typos false positives documentation]: https://github.com/crate-ci/typos#false-positives
2 changes: 1 addition & 1 deletion Docs/DefiniteInitialization.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Definite (De)Initialization

Definite (De)Initialization (DI, a.k.a. [definite assignment analyis](https://en.wikipedia.org/wiki/Definite_assignment_analysis) is a mandatory transformation pass that is applied on Hylo's intermediate representation, before code generation.
Definite (De)Initialization (DI, a.k.a. [definite assignment analysis](https://en.wikipedia.org/wiki/Definite_assignment_analysis) is a mandatory transformation pass that is applied on Hylo's intermediate representation, before code generation.
This pass ensures that all objects are initialized before use (definite initialization) and deinitialized before the end of their storage's lifetime (definite deinitialization), inserting additional instructions if necessary.

The pass is expected to run early in the IR transformation pipeline, after __Implicit Return Insertion__ and __Unreachable Code Elimination__.
Expand Down
2 changes: 1 addition & 1 deletion Docs/RemoteParts.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The compiler should emit a warning if a remote part is taken as a parameter of a
Local `var` bindings operate differently than stored `var` properties.
When we assign into a local `var`, the value that it held is destroyed (unless we do the `copy(into:)` optimization).
When we assign into a stored `var`, the value of its container is modified in place.
The thoeretical rationale is that a dotted access is always projection: the LHS of `foo.bar = 2` is not actually a `var`.
The theoretical rationale is that a dotted access is always projection: the LHS of `foo.bar = 2` is not actually a `var`.
Example:

```
Expand Down
2 changes: 1 addition & 1 deletion Docs/Subscripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ These two restrictions serve two goals:
1. Guarantee that continuations cannot break control flow and cannot.
2. Handle overlapping projections that do not nest.

One over-approximation of a continuation's scope is the dominance frontier of the basic block in which the projection starts, excluding the instructions before the start of the projeciton.
One over-approximation of a continuation's scope is the dominance frontier of the basic block in which the projection starts, excluding the instructions before the start of the projection.
In the above example, the continuation associated with `t` would contain all instructions in `loop.body` after the definition of `%t`.

Using dominance frontiers also obviates the difficulty to identify definitions may escape a continuation.
Expand Down
8 changes: 4 additions & 4 deletions Library/Hylo/Core/Bitcast.hylo
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/// Projects `value` with its memory representation reinterpreted as a value of type `U`.
public subscript unsafe_bitcast<T, U>(_ value: T): U {
let {
sink let p = Pointer<T>.to[value].copy().value
yield p as* (remote let U)
sink let p: Pointer<U> = Pointer(type_punning: pointer[to: value])
yield p.unsafe[]
}
inout {
sink let p = Pointer<T>.to[value].copy().value
yield &(p as* (remote inout U))
sink let p: PointerToMutable<U> = PointerToMutable(type_punning: pointerToMutable[&value])
yield &p.unsafe[]
}
}
42 changes: 42 additions & 0 deletions Library/Hylo/Core/CVoidPointer.hylo
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This type only exists because we don't seem to be able to make generic types like Pointer ForeignConvertible.
/// A pointer type for use in @ffi signatures.
type CVoidPointer: Regular {

/// The underlying representation.
var base: Builtin.ptr

memberwise init

}

public conformance CVoidPointer: ForeignConvertible {

public typealias ForeignRepresentation = Builtin.ptr

public init(foreign_value: sink Builtin.ptr) {
&self.base = foreign_value
}

public fun foreign_value() -> Builtin.ptr {
base
}

}

public conformance CVoidPointer: Copyable {

/// Returns an equivalent instance.
public fun copy() -> Self {
CVoidPointer(base: base)
}

}

public conformance CVoidPointer: Equatable {

/// Returns `true` iff `other` has an equivalent value.
public fun infix== (_ other: Self) -> Bool {
Bool(value: Builtin.icmp_eq_ptr(base, other.base))
}

}
22 changes: 22 additions & 0 deletions Library/Hylo/Core/Comparable.hylo
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// A type whose instances' values have a standard total ordering
///
/// `<` is a total ordering; `a == b` implies that `a < b` and `b < a` are both false.
public trait Comparable: Equatable {

/// Returns `true` iff `self` is ordered before `other`.
fun infix< (_ other: Self) -> Bool

}

extension Comparable {

/// Returns `true` iff `self` is ordered after `other`.
fun infix> (_ other: Self) -> Bool { (other < self) }

/// Returns `false` iff `self` is ordered after `other`.
fun infix<= (_ other: Self) -> Bool { !(other < self) }

/// Returns `false` iff `self` is ordered before `other`.
fun infix>= (_ other: Self) -> Bool { !(self < other) }

}
17 changes: 17 additions & 0 deletions Library/Hylo/Core/Equatable.hylo
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// A type whose instances' values can be compared for equivalence.
///
/// `==` is an equivalence relation; i.e. `a == a`, `a == b` ⟺ `b == a`, and `a == b` ∧ `b == c` ⟹
/// `a == c`.
public trait Equatable {

/// Returns `true` iff `other` has an equivalent value.
fun infix== (_ other: Self) -> Bool

}

extension Equatable {

/// Returns `false` iff `other` has an equivalent value.
public fun infix!= (_ other: Self) -> Bool { !(self == other) }

}
4 changes: 2 additions & 2 deletions Library/Hylo/Core/Int.hylo
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public type Int {
}

/// Creates an instance with the same memory representation as `address`.
public init(bit_pattern address: RawPointer) {
&self.value = Builtin.ptrtoint_word(address.value)
public init(bit_pattern address: PointerToMutable<Never>) {
&self.value = Builtin.ptrtoint_word(address.base)
}

/// Returns the absolute value of `self`.
Expand Down
13 changes: 13 additions & 0 deletions Library/Hylo/Core/MemoryAddress.hylo
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Can't really use this for anything yet due to https://github.com/hylo-lang/hylo/issues/936
/// A memory address.
typealias MemoryAddress = PointerToMutable<Never>

public extension PointerToMutable where Pointee == Never {

/// Creates an instance pointing to the same address as `p`
public init<T>(_ p: PointerToMutable<T>) { &self.base = p.base }

/// Creates an instance pointing to the same address as `p`
public init<T>(_ p: Pointer<T>) { &self.base = p.base }

}
8 changes: 2 additions & 6 deletions Library/Hylo/Core/MemoryLayout.hylo
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ public type MemoryLayout<T> {
/// The contiguous memory footprint of the `T`'s instances, in bytes.
public static fun size() -> Int {
let p: Pointer<Runtime.MetatypeHeader> = unsafe_bitcast[T]
return p.with_pointee(fun (_ h) -> Int {
h.size.copy()
})
return p.unsafe[].size.copy()
}

/// The preferred memory alignment of the `T`'s instances, in bytes.
public static fun alignment() -> Int {
let p: Pointer<Runtime.MetatypeHeader> = unsafe_bitcast[T]
return p.with_pointee(fun (_ h) -> Int {
h.alignment.copy()
})
return p.unsafe[].alignment.copy()
}

/// The number of bytes from the start of one instance of `T` to the start of the next when
Expand Down
37 changes: 0 additions & 37 deletions Library/Hylo/Core/MutablePointer.hylo

This file was deleted.

22 changes: 0 additions & 22 deletions Library/Hylo/Core/MutableRawPointer.hylo

This file was deleted.

Loading

0 comments on commit 7bf524f

Please sign in to comment.