Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into cp/edit-namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Jan 23, 2024
2 parents 4eafb67 + 7053432 commit 287dae5
Show file tree
Hide file tree
Showing 313 changed files with 5,587 additions and 8,318 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ on:
- trunk
tags:
- release/*
workflow_dispatch:


jobs:

Expand Down Expand Up @@ -229,11 +231,7 @@ jobs:
- name: unison-util-relation tests
run: stack --no-terminal build --fast --test unison-util-relation
- name: round-trip-tests
if: runner.os == 'macOS'
run: |
mkdir -p /private/tmp
touch /private/tmp/roundtrip.u
touch /private/tmp/rewrite-tmp.u
stack --no-terminal exec unison transcript unison-src/transcripts-round-trip/main.md
git add unison-src/transcripts-round-trip/main.output.md
# Fail if any transcripts cause git diffs.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ jobs:
- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "pre-release"
automatic_release_tag: "trunk-build"
prerelease: true
title: "Development Build"
files: |
Expand Down
89 changes: 89 additions & 0 deletions .github/workflows/update-transcripts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: update-transcripts

on:
workflow_dispatch:

jobs:
update_transcripts:
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
matrix:
os:
- macOS-12
steps:
- uses: actions/checkout@v4
- id: stackage-resolver
name: record stackage resolver
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
# looks for `resolver: nightly-yyyy-mm-dd` or `resolver: lts-xx.yy` in `stack.yaml` and splits it into
# `nightly` or `lts-xx`. the whole resolver string is put into resolver_long as a backup cache key
# ${{ steps.stackage-resolver.outputs.resolver_short }}
# ${{ steps.stackage-resolver.outputs.resolver_long }}
run: |
grep resolver stack.yaml | awk '{ x="resolver_short="; if (split($2,a,"-") > 2) print x a[1]; else {split($2,b,"."); print x b[1]}}' >> "$GITHUB_OUTPUT"
grep resolver stack.yaml | awk '{print "resolver_long="$2}' >> "$GITHUB_OUTPUT"
# Cache ~/.stack, keyed by the contents of 'stack.yaml'.
- uses: actions/cache@v3
name: cache ~/.stack (unix)
if: runner.os != 'Windows'
with:
path: ~/.stack
key: stack-1_${{matrix.os}}-${{ steps.stackage-resolver.outputs.resolver_long }}-${{hashFiles('**/stack.yaml')}}-${{github.sha}}
# Fall-back to use the most recent cache for the stack.yaml, or failing that the OS
restore-keys: |
stack-1_${{matrix.os}}-${{ steps.stackage-resolver.outputs.resolver_long }}-${{hashFiles('**/stack.yaml')}}-
stack-1_${{matrix.os}}-${{ steps.stackage-resolver.outputs.resolver_long }}-
stack-1_${{matrix.os}}-${{ steps.stackage-resolver.outputs.resolver_short }}-
stack-1_${{matrix.os}}-${{ steps.stackage-resolver.outputs.resolver_short }}.
stack-1_${{matrix.os}}-
# Cache each local package's ~/.stack-work for fast incremental builds in CI.
- uses: actions/cache@v3
name: cache .stack-work
with:
path: |
**/.stack-work
# Main cache key: commit hash. This should always result in a cache miss...
# So when loading a cache we'll always fall back to the restore-keys,
# which should load the most recent cache via a prefix search on the most
# recent branch cache.
# Then it will save a new cache at this commit sha, which should be used by
# the next build on this branch.
key: stack-work-4_${{matrix.os}}-${{ steps.stackage-resolver.outputs.resolver_short }}-${{hashFiles('**/stack.yaml')}}-${{github.sha}}
restore-keys: |
stack-work-4_${{matrix.os}}-${{ steps.stackage-resolver.outputs.resolver_long }}-${{hashFiles('**/stack.yaml')}}-
stack-work-4_${{matrix.os}}-${{ steps.stackage-resolver.outputs.resolver_long }}-
stack-work-4_${{matrix.os}}-${{ steps.stackage-resolver.outputs.resolver_short }}-
stack-work-4_${{matrix.os}}-${{ steps.stackage-resolver.outputs.resolver_short }}.
stack-work-4_${{matrix.os}}-
# Install stack by downloading the binary from GitHub.
# The installation process differs by OS.
- name: install stack (Linux)
if: runner.os == 'Linux'
working-directory: ${{ runner.temp }}
run: |
mkdir stack && cd stack
curl -L https://github.com/commercialhaskell/stack/releases/download/v2.9.1/stack-2.9.1-linux-x86_64.tar.gz | tar -xz
echo "$PWD/stack-"* >> $GITHUB_PATH
# One of the transcripts fails if the user's git name hasn't been set.
- name: set git user info
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
- name: build
run: stack --no-terminal build --fast --no-run-tests --test
- name: round-trip-tests
run: |
stack --no-terminal exec unison transcript unison-src/transcripts-round-trip/main.md
stack --no-terminal exec unison transcript unison-src/transcripts-manual/rewrites.md
- name: transcripts
run: stack --no-terminal exec transcripts
- name: save transcript changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: rerun transcripts (reminder to rerun CI!)
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM debian:stable

RUN adduser --home /unison --disabled-password unison

RUN apt-get update && \
apt-get install -y git libncurses5 less locales fzf && \
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8


COPY tmp/ucm/ucm /usr/local/bin/ucm
COPY tmp/ucm/ui /usr/local/share/ucm

ENV UCM_WEB_UI=/usr/local/share/ucm
ENV UCM_PORT=8080
ENV UCM_TOKEN=pub

RUN chmod 555 /usr/local/bin/ucm

EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/ucm"]
CMD ["--codebase","/unison"]
1 change: 1 addition & 0 deletions codebase2/codebase-sqlite-hashing-v2/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
- unison-hashing-v2
- unison-prelude
- unison-sqlite
- unison-syntax
- unison-util-base32hex
- unison-util-term
- vector
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module U.Codebase.Decl.Hashing where

import Control.Lens
import Data.Foldable qualified as Foldable
import Data.Map qualified as Map
import U.Codebase.Decl qualified as C
import U.Codebase.Decl qualified as C.Decl
import U.Codebase.HashTags
import U.Codebase.Reference qualified as Reference
import U.Codebase.Sqlite.Decl.Format qualified as DeclFormat
import U.Codebase.Sqlite.HashHandle (HashMismatch (..))
import U.Codebase.Sqlite.HashHandle qualified as HH
import U.Codebase.Sqlite.LocalIds qualified as LocalIds
import U.Codebase.Sqlite.Queries qualified as Q
import U.Codebase.Sqlite.Symbol qualified as S
import U.Codebase.Sqlite.Symbol qualified as Sqlite
import Unison.Hash32
import Unison.Hash32 qualified as Hash32
import Unison.Hashing.V2 qualified as H2
import Unison.Hashing.V2.Convert2 qualified as H2
import Unison.Prelude
import Unison.Symbol qualified as Unison
import Unison.Syntax.Name qualified as Name
import Unison.Var qualified as Var

verifyDeclFormatHash :: ComponentHash -> DeclFormat.HashDeclFormat -> Maybe HH.DeclHashingError
verifyDeclFormatHash (ComponentHash hash) (DeclFormat.Decl (DeclFormat.LocallyIndexedComponent elements)) =
Foldable.toList elements
& fmap s2cDecl
& Reference.component hash
& fmap (\(decl, refId) -> (refId, (C.Decl.vmap symbol2to1 decl, ())))
& Map.fromList
& C.Decl.unhashComponent hash Var.unnamedRef
& Map.toList
& fmap (\(_refId, (v, decl, ())) -> (v, either H2.toDataDecl id $ H2.v2ToH2Decl decl))
& Map.fromList
& H2.hashDecls Name.unsafeFromVar
& \case
Left _err -> Just HH.DeclHashResolutionFailure
Right m ->
m
& altMap \(_, H2.ReferenceId hash' _, _) ->
if hash == hash'
then Nothing
else Just (HH.DeclHashMismatch $ HashMismatch hash hash')
where
symbol2to1 :: S.Symbol -> Unison.Symbol
symbol2to1 (S.Symbol i t) = Unison.Symbol i (Var.User t)

s2cDecl :: (LocalIds.LocalIds' Text Hash32, DeclFormat.Decl Sqlite.Symbol) -> C.Decl Sqlite.Symbol
s2cDecl (ids, decl) =
let Identity (substText, substHash) = Q.localIdsToLookups Identity pure (bimap id Hash32.toHash ids)
refmap = (bimap substText (fmap substHash))
in Q.x2cDecl refmap decl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import Data.Function ((&))
import Data.Set qualified as Set
import U.Codebase.Branch.Hashing qualified as H2
import U.Codebase.Causal.Hashing qualified as H2
import U.Codebase.HashTags (BranchHash (..))
import U.Codebase.Decl.Hashing qualified as H2
import U.Codebase.HashTags (BranchHash (..), PatchHash (..))
import U.Codebase.Sqlite.Branch.Format qualified as BranchFormat
import U.Codebase.Sqlite.HashHandle
import U.Codebase.Sqlite.Patch.Format qualified as PatchFormat
import U.Codebase.Term.Hashing as H2
import U.Util.Type (removeAllEffectVars)
import Unison.Hashing.V2 qualified as H2
import Unison.Hashing.V2.Convert2 (h2ToV2Reference, hashBranchFormatToH2Branch, v2ToH2Type, v2ToH2TypeD)
import Unison.Hashing.V2.Convert2 (h2ToV2Reference, hashBranchFormatToH2Branch, hashPatchFormatToH2Patch, v2ToH2Type, v2ToH2TypeD)

v2HashHandle :: HashHandle
v2HashHandle =
Expand All @@ -25,10 +27,19 @@ v2HashHandle =
hashBranch = H2.hashBranch,
hashBranchV3 = H2.hashBranchV3,
hashCausal = H2.hashCausal,
hashBranchFormatFull = \localIds localBranch ->
BranchFormat.localToHashBranch localIds localBranch
& hashBranchFormatToH2Branch
& H2.contentHash
& BranchHash,
verifyTermFormatHash = H2.verifyTermFormatHash
hashBranchFormatFull,
hashPatchFormatFull,
verifyTermFormatHash = H2.verifyTermFormatHash,
verifyDeclFormatHash = H2.verifyDeclFormatHash
}
where
hashBranchFormatFull localIds localBranch =
BranchFormat.localToHashBranch localIds localBranch
& hashBranchFormatToH2Branch
& H2.contentHash
& BranchHash
hashPatchFormatFull localIds localPatch =
PatchFormat.localPatchToHashPatch localIds localPatch
& hashPatchFormatToH2Patch
& H2.contentHash
& PatchHash
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@ module Unison.Hashing.V2.Convert2
v2ToH2Type,
v2ToH2TypeD,
h2ToV2Reference,
v2ToH2Referent,
v2ToH2Branch,
v2ToH2Term,
v2ToH2Decl,
hashBranchFormatToH2Branch,
hashPatchFormatToH2Patch,
)
where

import Data.Map qualified as Map
import Data.Set qualified as Set
import Data.Text qualified as Text
import U.Codebase.Branch qualified as V2
import U.Codebase.Branch qualified as V2Branch
import U.Codebase.BranchV3 (BranchV3 (..))
import U.Codebase.Causal qualified as Causal
import U.Codebase.Decl qualified as V2.Decl
import U.Codebase.HashTags
import U.Codebase.Kind qualified as V2
import U.Codebase.Reference qualified as V2
import U.Codebase.Reference qualified as V2Reference
import U.Codebase.Referent qualified as V2Referent
import U.Codebase.Sqlite.Branch.Full qualified as Memory.BranchFull
import U.Codebase.Sqlite.Patch.Full qualified as Memory.PatchFull
import U.Codebase.Sqlite.Patch.TermEdit qualified as Memory.TermEdit
import U.Codebase.Sqlite.Patch.TypeEdit qualified as Memory.TypeEdit
import U.Codebase.Term qualified as V2 (TypeRef)
import U.Codebase.Term qualified as V2.Term
import U.Codebase.Type qualified as V2.Type
Expand All @@ -30,6 +38,7 @@ import Unison.Hash (Hash)
import Unison.Hashing.V2 qualified as H2
import Unison.NameSegment (NameSegment (..))
import Unison.Prelude
import Unison.Symbol qualified as Unison
import Unison.Util.Map qualified as Map

-- | Convert a V3 branch to a hashing branch.
Expand Down Expand Up @@ -135,6 +144,29 @@ hashBranchFormatToH2Branch Memory.BranchFull.Branch {terms, types, patches, chil
V2Referent.Con typeRef conId -> do
(H2.ReferentCon (v2ToH2Reference $ second unComponentHash typeRef) conId)

hashPatchFormatToH2Patch :: Memory.PatchFull.HashPatch -> H2.Patch
hashPatchFormatToH2Patch Memory.PatchFull.Patch {termEdits, typeEdits} =
H2.Patch
{ termEdits = Map.bimap cvreferent (Set.map cvTermEdit) termEdits,
typeEdits = Map.bimap cvreference (Set.map cvTypeEdit) typeEdits
}
where
cvTermEdit :: Memory.TermEdit.HashTermEdit -> H2.TermEdit
cvTermEdit = \case
Memory.TermEdit.Replace ref _typing -> H2.TermEditReplace (v2ToH2Referent . coerce $ ref)
Memory.TermEdit.Deprecate -> H2.TermEditDeprecate
cvTypeEdit :: Memory.TypeEdit.HashTypeEdit -> H2.TypeEdit
cvTypeEdit = \case
Memory.TypeEdit.Replace ref -> H2.TypeEditReplace (v2ToH2Reference . coerce $ ref)
Memory.TypeEdit.Deprecate -> H2.TypeEditDeprecate
cvreference :: V2Reference.Reference' Text ComponentHash -> H2.Reference
cvreference = v2ToH2Reference . second unComponentHash
cvreferent :: Memory.BranchFull.Referent'' Text ComponentHash -> H2.Referent
cvreferent = \case
V2Referent.Ref ref -> (H2.ReferentRef (v2ToH2Reference $ second unComponentHash ref))
V2Referent.Con typeRef conId -> do
(H2.ReferentCon (v2ToH2Reference $ second unComponentHash typeRef) conId)

v2ToH2Term :: forall v. Ord v => V2.Term.HashableTerm v -> H2.Term v ()
v2ToH2Term = ABT.transform convertF
where
Expand Down Expand Up @@ -189,3 +221,27 @@ v2ToH2Term = ABT.transform convertF
V2.Term.PCons -> H2.Cons
V2.Term.PSnoc -> H2.Snoc
V2.Term.PConcat -> H2.Concat

v2ToH2Decl :: V2.Decl.HashableDecl Unison.Symbol -> H2.Decl Unison.Symbol ()
v2ToH2Decl (V2.Decl.DataDeclaration {declType, modifier, bound, constructorTypes}) =
let tag = case declType of
V2.Decl.Effect -> Left . H2.EffectDeclaration
V2.Decl.Data -> Right
in tag $
H2.DataDeclaration
{ modifier = v2ToH2Modifier modifier,
annotation = (),
bound = bound,
constructors' =
constructorTypes
& zip [0 ..]
& fmap mkCtor
}
where
mkCtor :: (Int, V2.Type.TypeR V2.Decl.HashableTypeRef Unison.Symbol) -> ((), Unison.Symbol, H2.Type Unison.Symbol ())
mkCtor (n, t) = ((), Unison.symbol . Text.pack $ "Constructor" ++ show n, v2ToH2Type t)

v2ToH2Modifier :: V2.Decl.Modifier -> H2.Modifier
v2ToH2Modifier = \case
V2.Decl.Structural -> H2.Structural
V2.Decl.Unique t -> H2.Unique t
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ library
other-modules:
U.Codebase.Branch.Hashing
U.Codebase.Causal.Hashing
U.Codebase.Decl.Hashing
U.Codebase.Term.Hashing
Unison.Hashing.V2.Convert2
hs-source-dirs:
Expand Down Expand Up @@ -69,6 +70,7 @@ library
, unison-hashing-v2
, unison-prelude
, unison-sqlite
, unison-syntax
, unison-util-base32hex
, unison-util-term
, vector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module U.Codebase.Sqlite.Branch.Format
localToDbBranch,
localToDbDiff,
localToHashBranch,
localToBranch,
-- dbToLocalDiff,
)
where
Expand Down
Loading

0 comments on commit 287dae5

Please sign in to comment.