From 8bf550e616acdf226df60a7d4ae8ed1bb53f09a6 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 29 Apr 2023 12:00:43 +0000 Subject: [PATCH 01/89] Merge commit 'ef07e8e60f994ec014d049a95591426fb92ebb79' into sync_cg_clif-2023-04-29 --- .github/actions/github-release/README.md | 18 + .github/actions/github-release/action.yml | 13 + .github/actions/github-release/main.js | 162 +++++ .../actions/github-release/package-lock.json | 571 ++++++++++++++++++ .github/actions/github-release/package.json | 11 + .github/workflows/abi-cafe.yml | 7 - .github/workflows/main.yml | 62 +- .github/workflows/rustc.yml | 18 +- Cargo.lock | 143 ++--- Cargo.toml | 16 +- Readme.md | 5 +- build_sysroot/Cargo.lock | 28 +- build_system/mod.rs | 2 +- build_system/tests.rs | 29 +- example/alloc_example.rs | 2 +- ...itrary_self_types_pointers_and_wrappers.rs | 3 +- example/dst-field-align.rs | 41 +- example/example.rs | 6 +- example/issue-72793.rs | 4 +- example/issue-91827-extern-types.rs | 5 +- example/mini_core.rs | 52 +- example/mini_core_hello_world.rs | 3 +- example/mod_bench.rs | 8 +- example/std_example.rs | 27 +- example/subslice-patterns-const-eval.rs | 11 +- rust-toolchain | 2 +- scripts/cargo-clif.rs | 2 +- scripts/rustc-clif.rs | 8 +- scripts/rustdoc-clif.rs | 8 +- scripts/test_rustc_tests.sh | 72 ++- src/abi/comments.rs | 32 +- src/abi/mod.rs | 4 +- src/abi/pass_mode.rs | 4 +- src/abi/returning.rs | 4 +- src/base.rs | 54 +- src/cast.rs | 2 +- src/codegen_i128.rs | 153 ++--- src/common.rs | 26 +- src/concurrency_limiter.rs | 67 +- src/constant.rs | 2 + src/driver/aot.rs | 6 +- src/driver/jit.rs | 4 + src/driver/mod.rs | 29 + src/global_asm.rs | 1 - src/intrinsics/mod.rs | 12 +- src/intrinsics/simd.rs | 2 +- src/lib.rs | 2 +- src/num.rs | 4 +- src/pretty_clif.rs | 57 +- src/value_and_place.rs | 334 ++++------ y.rs | 6 +- 51 files changed, 1469 insertions(+), 675 deletions(-) create mode 100644 .github/actions/github-release/README.md create mode 100644 .github/actions/github-release/action.yml create mode 100644 .github/actions/github-release/main.js create mode 100644 .github/actions/github-release/package-lock.json create mode 100644 .github/actions/github-release/package.json diff --git a/.github/actions/github-release/README.md b/.github/actions/github-release/README.md new file mode 100644 index 00000000000..c70ba8f4953 --- /dev/null +++ b/.github/actions/github-release/README.md @@ -0,0 +1,18 @@ +# github-release + +An action used to publish GitHub releases for `wasmtime`. + +As of the time of this writing there's a few actions floating around which +perform github releases but they all tend to have their set of drawbacks. +Additionally nothing handles deleting releases which we need for our rolling +`dev` release. + +To handle all this this action rolls-its-own implementation using the +actions/toolkit repository and packages published there. These run in a Docker +container and take various inputs to orchestrate the release from the build. + +More comments can be found in `main.js`. + +Testing this is really hard. If you want to try though run `npm install` and +then `node main.js`. You'll have to configure a bunch of env vars though to get +anything reasonably working. diff --git a/.github/actions/github-release/action.yml b/.github/actions/github-release/action.yml new file mode 100644 index 00000000000..36e5209f50c --- /dev/null +++ b/.github/actions/github-release/action.yml @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +name: 'rustc_codegen_cranelift github releases' +description: 'rustc_codegen_cranelift github releases' +inputs: + token: + description: '' + required: true + files: + description: '' + required: true +runs: + using: 'node16' + main: 'main.js' diff --git a/.github/actions/github-release/main.js b/.github/actions/github-release/main.js new file mode 100644 index 00000000000..6fcfca34ea7 --- /dev/null +++ b/.github/actions/github-release/main.js @@ -0,0 +1,162 @@ +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +const core = require('@actions/core'); +const path = require("path"); +const fs = require("fs"); +const github = require('@actions/github'); +const glob = require('glob'); + +function sleep(milliseconds) { + return new Promise(resolve => setTimeout(resolve, milliseconds)) +} + +async function runOnce() { + // Load all our inputs and env vars. Note that `getInput` reads from `INPUT_*` + const files = core.getInput('files'); + const token = core.getInput('token'); + const slug = process.env.GITHUB_REPOSITORY; + const owner = slug.split('/')[0]; + const repo = slug.split('/')[1]; + const sha = process.env.GITHUB_SHA; + let name = 'dev'; + if (process.env.GITHUB_REF.startsWith('refs/tags/v')) { + name = process.env.GITHUB_REF.substring(10); + } + + core.info(`files: ${files}`); + core.info(`name: ${name}`); + core.info(`token: ${token}`); + + const octokit = github.getOctokit(token); + + // For the `dev` release we may need to update the tag to point to the new + // commit on this branch. All other names should already have tags associated + // with them. + if (name == 'dev') { + let tag = null; + try { + tag = await octokit.request("GET /repos/:owner/:repo/git/refs/tags/:name", { owner, repo, name }); + core.info(`found existing tag`); + console.log("tag: ", JSON.stringify(tag.data, null, 2)); + } catch (e) { + // ignore if this tag doesn't exist + core.info(`no existing tag found`); + } + + if (tag === null || tag.data.object.sha !== sha) { + core.info(`updating existing tag or creating new one`); + + try { + core.info(`updating dev tag`); + await octokit.rest.git.updateRef({ + owner, + repo, + ref: 'tags/dev', + sha, + force: true, + }); + } catch (e) { + console.log("ERROR: ", JSON.stringify(e.data, null, 2)); + core.info(`creating dev tag`); + try { + await octokit.rest.git.createRef({ + owner, + repo, + ref: 'refs/tags/dev', + sha, + }); + } catch (e) { + // we might race with others, so assume someone else has created the + // tag by this point. + console.log("failed to create tag: ", JSON.stringify(e.data, null, 2)); + } + } + + console.log("double-checking tag is correct"); + tag = await octokit.request("GET /repos/:owner/:repo/git/refs/tags/:name", { owner, repo, name }); + if (tag.data.object.sha !== sha) { + console.log("tag: ", JSON.stringify(tag.data, null, 2)); + throw new Error("tag didn't work"); + } + } else { + core.info(`existing tag works`); + } + } + + // Delete a previous release + try { + core.info(`fetching release`); + let release = await octokit.rest.repos.getReleaseByTag({ owner, repo, tag: name }); + console.log("found release: ", JSON.stringify(release.data, null, 2)); + await octokit.rest.repos.deleteRelease({ + owner, + repo, + release_id: release.data.id, + }); + console.log("deleted release"); + } catch (e) { + console.log("ERROR: ", JSON.stringify(e, null, 2)); + } + + console.log("creating a release"); + let release = await octokit.rest.repos.createRelease({ + owner, + repo, + tag_name: name, + prerelease: name === 'dev', + }); + + // Delete all assets from a previous run + for (const asset of release.data.assets) { + console.log(`deleting prior asset ${asset.id}`); + await octokit.rest.repos.deleteReleaseAsset({ + owner, + repo, + asset_id: asset.id, + }); + } + + // Upload all the relevant assets for this release as just general blobs. + for (const file of glob.sync(files)) { + const size = fs.statSync(file).size; + const name = path.basename(file); + core.info(`upload ${file}`); + await octokit.rest.repos.uploadReleaseAsset({ + data: fs.createReadStream(file), + headers: { 'content-length': size, 'content-type': 'application/octet-stream' }, + name, + url: release.data.upload_url, + }); + } +} + +async function run() { + const retries = 10; + for (let i = 0; i < retries; i++) { + try { + await runOnce(); + break; + } catch (e) { + if (i === retries - 1) + throw e; + logError(e); + console.log("RETRYING after 10s"); + await sleep(10000) + } + } +} + +function logError(e) { + console.log("ERROR: ", e.message); + try { + console.log(JSON.stringify(e, null, 2)); + } catch (e) { + // ignore json errors for now + } + console.log(e.stack); +} + +run().catch(err => { + logError(err); + core.setFailed(err.message); +}); diff --git a/.github/actions/github-release/package-lock.json b/.github/actions/github-release/package-lock.json new file mode 100644 index 00000000000..dd3b2a048f0 --- /dev/null +++ b/.github/actions/github-release/package-lock.json @@ -0,0 +1,571 @@ +{ + "name": "rustc_codegen_cranelift-github-release", + "version": "0.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "rustc_codegen_cranelift-github-release", + "version": "0.0.0", + "dependencies": { + "@actions/core": "^1.9.1", + "@actions/github": "^5.1.0", + "glob": "^7.1.5" + } + }, + "node_modules/@actions/core": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz", + "integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==", + "dependencies": { + "@actions/http-client": "^2.0.1", + "uuid": "^8.3.2" + } + }, + "node_modules/@actions/github": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-5.1.0.tgz", + "integrity": "sha512-tuI80F7JQIhg77ZTTgUAPpVD7ZnP9oHSPN8xw7LOwtA4vEMbAjWJNbmLBfV7xua7r016GyjzWLuec5cs8f/a8A==", + "dependencies": { + "@actions/http-client": "^2.0.1", + "@octokit/core": "^3.6.0", + "@octokit/plugin-paginate-rest": "^2.17.0", + "@octokit/plugin-rest-endpoint-methods": "^5.13.0" + } + }, + "node_modules/@actions/http-client": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz", + "integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==", + "dependencies": { + "tunnel": "^0.0.6" + } + }, + "node_modules/@octokit/auth-token": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.5.0.tgz", + "integrity": "sha512-r5FVUJCOLl19AxiuZD2VRZ/ORjp/4IN98Of6YJoJOkY75CIBuYfmiNHGrDwXr+aLGG55igl9QrxX3hbiXlLb+g==", + "dependencies": { + "@octokit/types": "^6.0.3" + } + }, + "node_modules/@octokit/core": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.6.0.tgz", + "integrity": "sha512-7RKRKuA4xTjMhY+eG3jthb3hlZCsOwg3rztWh75Xc+ShDWOfDDATWbeZpAHBNRpm4Tv9WgBMOy1zEJYXG6NJ7Q==", + "dependencies": { + "@octokit/auth-token": "^2.4.4", + "@octokit/graphql": "^4.5.8", + "@octokit/request": "^5.6.3", + "@octokit/request-error": "^2.0.5", + "@octokit/types": "^6.0.3", + "before-after-hook": "^2.2.0", + "universal-user-agent": "^6.0.0" + } + }, + "node_modules/@octokit/endpoint": { + "version": "6.0.12", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-6.0.12.tgz", + "integrity": "sha512-lF3puPwkQWGfkMClXb4k/eUT/nZKQfxinRWJrdZaJO85Dqwo/G0yOC434Jr2ojwafWJMYqFGFa5ms4jJUgujdA==", + "dependencies": { + "@octokit/types": "^6.0.3", + "is-plain-object": "^5.0.0", + "universal-user-agent": "^6.0.0" + } + }, + "node_modules/@octokit/graphql": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.8.0.tgz", + "integrity": "sha512-0gv+qLSBLKF0z8TKaSKTsS39scVKF9dbMxJpj3U0vC7wjNWFuIpL/z76Qe2fiuCbDRcJSavkXsVtMS6/dtQQsg==", + "dependencies": { + "@octokit/request": "^5.6.0", + "@octokit/types": "^6.0.3", + "universal-user-agent": "^6.0.0" + } + }, + "node_modules/@octokit/openapi-types": { + "version": "12.11.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", + "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==" + }, + "node_modules/@octokit/plugin-paginate-rest": { + "version": "2.21.3", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.21.3.tgz", + "integrity": "sha512-aCZTEf0y2h3OLbrgKkrfFdjRL6eSOo8komneVQJnYecAxIej7Bafor2xhuDJOIFau4pk0i/P28/XgtbyPF0ZHw==", + "dependencies": { + "@octokit/types": "^6.40.0" + }, + "peerDependencies": { + "@octokit/core": ">=2" + } + }, + "node_modules/@octokit/plugin-rest-endpoint-methods": { + "version": "5.16.2", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.16.2.tgz", + "integrity": "sha512-8QFz29Fg5jDuTPXVtey05BLm7OB+M8fnvE64RNegzX7U+5NUXcOcnpTIK0YfSHBg8gYd0oxIq3IZTe9SfPZiRw==", + "dependencies": { + "@octokit/types": "^6.39.0", + "deprecation": "^2.3.1" + }, + "peerDependencies": { + "@octokit/core": ">=3" + } + }, + "node_modules/@octokit/request": { + "version": "5.6.3", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.3.tgz", + "integrity": "sha512-bFJl0I1KVc9jYTe9tdGGpAMPy32dLBXXo1dS/YwSCTL/2nd9XeHsY616RE3HPXDVk+a+dBuzyz5YdlXwcDTr2A==", + "dependencies": { + "@octokit/endpoint": "^6.0.1", + "@octokit/request-error": "^2.1.0", + "@octokit/types": "^6.16.1", + "is-plain-object": "^5.0.0", + "node-fetch": "^2.6.7", + "universal-user-agent": "^6.0.0" + } + }, + "node_modules/@octokit/request-error": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.1.0.tgz", + "integrity": "sha512-1VIvgXxs9WHSjicsRwq8PlR2LR2x6DwsJAaFgzdi0JfJoGSO8mYI/cHJQ+9FbN21aa+DrgNLnwObmyeSC8Rmpg==", + "dependencies": { + "@octokit/types": "^6.0.3", + "deprecation": "^2.0.0", + "once": "^1.4.0" + } + }, + "node_modules/@octokit/types": { + "version": "6.41.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", + "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", + "dependencies": { + "@octokit/openapi-types": "^12.11.0" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "node_modules/before-after-hook": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", + "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==" + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, + "node_modules/deprecation": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", + "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + }, + "node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/is-plain-object": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, + "node_modules/universal-user-agent": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz", + "integrity": "sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==" + }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + } + }, + "dependencies": { + "@actions/core": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz", + "integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==", + "requires": { + "@actions/http-client": "^2.0.1", + "uuid": "^8.3.2" + } + }, + "@actions/github": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-5.1.0.tgz", + "integrity": "sha512-tuI80F7JQIhg77ZTTgUAPpVD7ZnP9oHSPN8xw7LOwtA4vEMbAjWJNbmLBfV7xua7r016GyjzWLuec5cs8f/a8A==", + "requires": { + "@actions/http-client": "^2.0.1", + "@octokit/core": "^3.6.0", + "@octokit/plugin-paginate-rest": "^2.17.0", + "@octokit/plugin-rest-endpoint-methods": "^5.13.0" + } + }, + "@actions/http-client": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz", + "integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==", + "requires": { + "tunnel": "^0.0.6" + } + }, + "@octokit/auth-token": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.5.0.tgz", + "integrity": "sha512-r5FVUJCOLl19AxiuZD2VRZ/ORjp/4IN98Of6YJoJOkY75CIBuYfmiNHGrDwXr+aLGG55igl9QrxX3hbiXlLb+g==", + "requires": { + "@octokit/types": "^6.0.3" + } + }, + "@octokit/core": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.6.0.tgz", + "integrity": "sha512-7RKRKuA4xTjMhY+eG3jthb3hlZCsOwg3rztWh75Xc+ShDWOfDDATWbeZpAHBNRpm4Tv9WgBMOy1zEJYXG6NJ7Q==", + "requires": { + "@octokit/auth-token": "^2.4.4", + "@octokit/graphql": "^4.5.8", + "@octokit/request": "^5.6.3", + "@octokit/request-error": "^2.0.5", + "@octokit/types": "^6.0.3", + "before-after-hook": "^2.2.0", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/endpoint": { + "version": "6.0.12", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-6.0.12.tgz", + "integrity": "sha512-lF3puPwkQWGfkMClXb4k/eUT/nZKQfxinRWJrdZaJO85Dqwo/G0yOC434Jr2ojwafWJMYqFGFa5ms4jJUgujdA==", + "requires": { + "@octokit/types": "^6.0.3", + "is-plain-object": "^5.0.0", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/graphql": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.8.0.tgz", + "integrity": "sha512-0gv+qLSBLKF0z8TKaSKTsS39scVKF9dbMxJpj3U0vC7wjNWFuIpL/z76Qe2fiuCbDRcJSavkXsVtMS6/dtQQsg==", + "requires": { + "@octokit/request": "^5.6.0", + "@octokit/types": "^6.0.3", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/openapi-types": { + "version": "12.11.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", + "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==" + }, + "@octokit/plugin-paginate-rest": { + "version": "2.21.3", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.21.3.tgz", + "integrity": "sha512-aCZTEf0y2h3OLbrgKkrfFdjRL6eSOo8komneVQJnYecAxIej7Bafor2xhuDJOIFau4pk0i/P28/XgtbyPF0ZHw==", + "requires": { + "@octokit/types": "^6.40.0" + } + }, + "@octokit/plugin-rest-endpoint-methods": { + "version": "5.16.2", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.16.2.tgz", + "integrity": "sha512-8QFz29Fg5jDuTPXVtey05BLm7OB+M8fnvE64RNegzX7U+5NUXcOcnpTIK0YfSHBg8gYd0oxIq3IZTe9SfPZiRw==", + "requires": { + "@octokit/types": "^6.39.0", + "deprecation": "^2.3.1" + } + }, + "@octokit/request": { + "version": "5.6.3", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.3.tgz", + "integrity": "sha512-bFJl0I1KVc9jYTe9tdGGpAMPy32dLBXXo1dS/YwSCTL/2nd9XeHsY616RE3HPXDVk+a+dBuzyz5YdlXwcDTr2A==", + "requires": { + "@octokit/endpoint": "^6.0.1", + "@octokit/request-error": "^2.1.0", + "@octokit/types": "^6.16.1", + "is-plain-object": "^5.0.0", + "node-fetch": "^2.6.7", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/request-error": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.1.0.tgz", + "integrity": "sha512-1VIvgXxs9WHSjicsRwq8PlR2LR2x6DwsJAaFgzdi0JfJoGSO8mYI/cHJQ+9FbN21aa+DrgNLnwObmyeSC8Rmpg==", + "requires": { + "@octokit/types": "^6.0.3", + "deprecation": "^2.0.0", + "once": "^1.4.0" + } + }, + "@octokit/types": { + "version": "6.41.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", + "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", + "requires": { + "@octokit/openapi-types": "^12.11.0" + } + }, + "balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "before-after-hook": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", + "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==" + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, + "deprecation": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", + "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + }, + "glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "is-plain-object": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==" + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "requires": { + "whatwg-url": "^5.0.0" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==" + }, + "tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==" + }, + "universal-user-agent": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz", + "integrity": "sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==" + }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + }, + "webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "requires": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + } + } +} diff --git a/.github/actions/github-release/package.json b/.github/actions/github-release/package.json new file mode 100644 index 00000000000..d9c23f8873e --- /dev/null +++ b/.github/actions/github-release/package.json @@ -0,0 +1,11 @@ +{ + "name": "rustc_codegen_cranelift-github-release", + "version": "0.0.0", + "license": "Apache-2.0 WITH LLVM-exception", + "main": "main.js", + "dependencies": { + "@actions/core": "^1.9.1", + "@actions/github": "^5.1.0", + "glob": "^7.1.5" + } +} diff --git a/.github/workflows/abi-cafe.yml b/.github/workflows/abi-cafe.yml index 5f5510a5796..3c40555669c 100644 --- a/.github/workflows/abi-cafe.yml +++ b/.github/workflows/abi-cafe.yml @@ -45,13 +45,6 @@ jobs: if: matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' run: rustup set default-host x86_64-pc-windows-gnu - - name: Use sparse cargo registry - run: | - cat >> ~/.cargo/config.toml <> ~/.cargo/config.toml <> ~/.cargo/config.toml <> ~/.cargo/config.toml <> ~/.cargo/config.toml <> ~/.cargo/config.toml < Self { + fn new(dirs: Dirs, mut target_compiler: Compiler, is_native: bool) -> Self { if let Ok(rustflags) = env::var("RUSTFLAGS") { target_compiler.rustflags.push(' '); target_compiler.rustflags.push_str(&rustflags); @@ -297,7 +304,7 @@ impl TestRunner { Self { is_native, jit_supported, dirs, target_compiler } } - pub fn run_testsuite(&self, tests: &[TestCase]) { + fn run_testsuite(&self, tests: &[TestCase]) { for TestCase { config, cmd } in tests { let (tag, testname) = config.split_once('.').unwrap(); let tag = tag.to_uppercase(); @@ -382,7 +389,7 @@ impl TestRunner { spawn_and_wait(self.rustc_command(args)); } - fn run_out_command<'a>(&self, name: &str, args: &[&str]) { + fn run_out_command(&self, name: &str, args: &[&str]) { let mut full_cmd = vec![]; // Prepend the RUN_WRAPPER's diff --git a/example/alloc_example.rs b/example/alloc_example.rs index 4ede2fe4efe..d994e2fbc0a 100644 --- a/example/alloc_example.rs +++ b/example/alloc_example.rs @@ -18,7 +18,7 @@ extern "C" { } #[panic_handler] -fn panic_handler(_: &core::panic::PanicInfo) -> ! { +fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! { core::intrinsics::abort(); } diff --git a/example/arbitrary_self_types_pointers_and_wrappers.rs b/example/arbitrary_self_types_pointers_and_wrappers.rs index d270fec6b71..f7edfa960a2 100644 --- a/example/arbitrary_self_types_pointers_and_wrappers.rs +++ b/example/arbitrary_self_types_pointers_and_wrappers.rs @@ -3,8 +3,8 @@ #![feature(arbitrary_self_types, unsize, coerce_unsized, dispatch_from_dyn)] use std::{ - ops::{Deref, CoerceUnsized, DispatchFromDyn}, marker::Unsize, + ops::{CoerceUnsized, Deref, DispatchFromDyn}, }; struct Ptr(Box); @@ -33,7 +33,6 @@ impl Deref for Wrapper { impl, U> CoerceUnsized> for Wrapper {} impl, U> DispatchFromDyn> for Wrapper {} - trait Trait { // This method isn't object-safe yet. Unsized by-value `self` is object-safe (but not callable // without unsized_locals), but wrappers around `Self` currently are not. diff --git a/example/dst-field-align.rs b/example/dst-field-align.rs index 6c338e99912..22fc6ff33e3 100644 --- a/example/dst-field-align.rs +++ b/example/dst-field-align.rs @@ -2,7 +2,7 @@ #![allow(dead_code)] struct Foo { a: u16, - b: T + b: T, } trait Bar { @@ -10,58 +10,57 @@ trait Bar { } impl Bar for usize { - fn get(&self) -> usize { *self } + fn get(&self) -> usize { + *self + } } struct Baz { - a: T + a: T, } struct HasDrop { ptr: Box, - data: T + data: T, } fn main() { // Test that zero-offset works properly - let b : Baz = Baz { a: 7 }; + let b: Baz = Baz { a: 7 }; assert_eq!(b.a.get(), 7); - let b : &Baz = &b; + let b: &Baz = &b; assert_eq!(b.a.get(), 7); // Test that the field is aligned properly - let f : Foo = Foo { a: 0, b: 11 }; + let f: Foo = Foo { a: 0, b: 11 }; assert_eq!(f.b.get(), 11); - let ptr1 : *const u8 = &f.b as *const _ as *const u8; + let ptr1: *const u8 = &f.b as *const _ as *const u8; - let f : &Foo = &f; - let ptr2 : *const u8 = &f.b as *const _ as *const u8; + let f: &Foo = &f; + let ptr2: *const u8 = &f.b as *const _ as *const u8; assert_eq!(f.b.get(), 11); // The pointers should be the same assert_eq!(ptr1, ptr2); // Test that nested DSTs work properly - let f : Foo> = Foo { a: 0, b: Foo { a: 1, b: 17 }}; + let f: Foo> = Foo { a: 0, b: Foo { a: 1, b: 17 } }; assert_eq!(f.b.b.get(), 17); - let f : &Foo> = &f; + let f: &Foo> = &f; assert_eq!(f.b.b.get(), 17); // Test that get the pointer via destructuring works - let f : Foo = Foo { a: 0, b: 11 }; - let f : &Foo = &f; + let f: Foo = Foo { a: 0, b: 11 }; + let f: &Foo = &f; let &Foo { a: _, b: ref bar } = f; assert_eq!(bar.get(), 11); // Make sure that drop flags don't screw things up - let d : HasDrop> = HasDrop { - ptr: Box::new(0), - data: Baz { a: [1,2,3,4] } - }; - assert_eq!([1,2,3,4], d.data.a); + let d: HasDrop> = HasDrop { ptr: Box::new(0), data: Baz { a: [1, 2, 3, 4] } }; + assert_eq!([1, 2, 3, 4], d.data.a); - let d : &HasDrop> = &d; - assert_eq!(&[1,2,3,4], &d.data.a); + let d: &HasDrop> = &d; + assert_eq!(&[1, 2, 3, 4], &d.data.a); } diff --git a/example/example.rs b/example/example.rs index d5c122bf681..885e55bc764 100644 --- a/example/example.rs +++ b/example/example.rs @@ -11,11 +11,7 @@ pub fn abc(a: u8) -> u8 { } pub fn bcd(b: bool, a: u8) -> u8 { - if b { - a * 2 - } else { - a * 3 - } + if b { a * 2 } else { a * 3 } } pub fn call() { diff --git a/example/issue-72793.rs b/example/issue-72793.rs index b1bb9b8e1e7..166b0060043 100644 --- a/example/issue-72793.rs +++ b/example/issue-72793.rs @@ -2,7 +2,9 @@ #![feature(type_alias_impl_trait)] -trait T { type Item; } +trait T { + type Item; +} type Alias<'a> = impl T; diff --git a/example/issue-91827-extern-types.rs b/example/issue-91827-extern-types.rs index 03910069633..6f39c5edcad 100644 --- a/example/issue-91827-extern-types.rs +++ b/example/issue-91827-extern-types.rs @@ -40,10 +40,7 @@ impl ListImpl { } } -pub static A: ListImpl = ListImpl { - len: 3, - data: [5, 6, 7], -}; +pub static A: ListImpl = ListImpl { len: 3, data: [5, 6, 7] }; pub static A_REF: &'static List = A.as_list(); pub static A_TAIL_OFFSET: isize = tail_offset(A.as_list()); diff --git a/example/mini_core.rs b/example/mini_core.rs index 73b83b89f6d..ea97e9f060e 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -37,13 +37,13 @@ impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} pub trait DispatchFromDyn {} // &T -> &U -impl<'a, T: ?Sized+Unsize, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {} +impl<'a, T: ?Sized + Unsize, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {} // &mut T -> &mut U -impl<'a, T: ?Sized+Unsize, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {} +impl<'a, T: ?Sized + Unsize, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {} // *const T -> *const U -impl, U: ?Sized> DispatchFromDyn<*const U> for *const T {} +impl, U: ?Sized> DispatchFromDyn<*const U> for *const T {} // *mut T -> *mut U -impl, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {} +impl, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {} impl, U: ?Sized> DispatchFromDyn> for Box {} #[lang = "receiver"] @@ -288,7 +288,6 @@ impl PartialEq for u32 { } } - impl PartialEq for u64 { fn eq(&self, other: &u64) -> bool { (*self) == (*other) @@ -361,7 +360,7 @@ impl PartialEq for *const T { } } -impl PartialEq for Option { +impl PartialEq for Option { fn eq(&self, other: &Self) -> bool { match (self, other) { (Some(lhs), Some(rhs)) => *lhs == *rhs, @@ -472,7 +471,20 @@ pub fn panic(_msg: &'static str) -> ! { #[track_caller] fn panic_bounds_check(index: usize, len: usize) -> ! { unsafe { - libc::printf("index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, len, index); + libc::printf( + "index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, + len, + index, + ); + intrinsics::abort(); + } +} + +#[lang = "panic_cannot_unwind"] +#[track_caller] +fn panic_cannot_unwind() -> ! { + unsafe { + libc::puts("panic in a function that cannot unwind\n\0" as *const str as *const i8); intrinsics::abort(); } } @@ -599,7 +611,7 @@ pub mod libc { // functions. legacy_stdio_definitions.lib which provides the printf wrapper functions as normal // symbols to link against. #[cfg_attr(unix, link(name = "c"))] - #[cfg_attr(target_env="msvc", link(name="legacy_stdio_definitions"))] + #[cfg_attr(target_env = "msvc", link(name = "legacy_stdio_definitions"))] extern "C" { pub fn printf(format: *const i8, ...) -> i32; } @@ -638,7 +650,7 @@ impl Index for [T] { } } -extern { +extern "C" { type VaListImpl; } @@ -648,23 +660,33 @@ pub struct VaList<'a>(&'a mut VaListImpl); #[rustc_builtin_macro] #[rustc_macro_transparency = "semitransparent"] -pub macro stringify($($t:tt)*) { /* compiler built-in */ } +pub macro stringify($($t:tt)*) { + /* compiler built-in */ +} #[rustc_builtin_macro] #[rustc_macro_transparency = "semitransparent"] -pub macro file() { /* compiler built-in */ } +pub macro file() { + /* compiler built-in */ +} #[rustc_builtin_macro] #[rustc_macro_transparency = "semitransparent"] -pub macro line() { /* compiler built-in */ } +pub macro line() { + /* compiler built-in */ +} #[rustc_builtin_macro] #[rustc_macro_transparency = "semitransparent"] -pub macro cfg() { /* compiler built-in */ } +pub macro cfg() { + /* compiler built-in */ +} #[rustc_builtin_macro] #[rustc_macro_transparency = "semitransparent"] -pub macro global_asm() { /* compiler built-in */ } +pub macro global_asm() { + /* compiler built-in */ +} pub static A_STATIC: u8 = 42; @@ -676,7 +698,7 @@ struct PanicLocation { } #[no_mangle] -#[cfg(not(windows))] +#[cfg(not(all(windows, target_env = "gnu")))] pub fn get_tls() -> u8 { #[thread_local] static A: u8 = 42; diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 6ad3268e70d..5a55aa215bf 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -319,7 +319,7 @@ fn main() { from_decimal_string(); - #[cfg(not(any(jit, windows)))] + #[cfg(all(not(jit), not(all(windows, target_env = "gnu"))))] test_tls(); #[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))] @@ -524,6 +524,7 @@ pub enum E1 { // Computing the discriminant used to be done using the niche type (here `u8`, // from the `bool` field of `V1`), overflowing for variants with large enough // indices (`V3` and `V4`), causing them to be interpreted as other variants. +#[rustfmt::skip] pub enum E2 { V1 { f: bool }, diff --git a/example/mod_bench.rs b/example/mod_bench.rs index e3e8a3c2d6a..f15e48acc41 100644 --- a/example/mod_bench.rs +++ b/example/mod_bench.rs @@ -3,15 +3,15 @@ #[cfg_attr(unix, link(name = "c"))] #[cfg_attr(target_env = "msvc", link(name = "msvcrt"))] -extern {} +extern "C" {} #[panic_handler] -fn panic_handler(_: &core::panic::PanicInfo) -> ! { +fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! { core::intrinsics::abort(); } -#[lang="eh_personality"] -fn eh_personality(){} +#[lang = "eh_personality"] +fn eh_personality() {} // Required for rustc_codegen_llvm #[no_mangle] diff --git a/example/std_example.rs b/example/std_example.rs index e34b35d5c4a..ab4045d11a6 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -1,4 +1,4 @@ -#![feature(core_intrinsics, generators, generator_trait, is_sorted)] +#![feature(core_intrinsics, generators, generator_trait, is_sorted, repr_simd)] #[cfg(target_arch = "x86_64")] use std::arch::x86_64::*; @@ -56,7 +56,10 @@ fn main() { assert_eq!(0b0000000000000000000000000010000010000000000000000000000000000000_0000000000100000000000000000000000001000000000000100000000000000u128.leading_zeros(), 26); assert_eq!(0b0000000000000000000000000010000000000000000000000000000000000000_0000000000000000000000000000000000001000000000000000000010000000u128.trailing_zeros(), 7); - assert_eq!(core::intrinsics::saturating_sub(0, -170141183460469231731687303715884105728i128), 170141183460469231731687303715884105727i128); + assert_eq!( + core::intrinsics::saturating_sub(0, -170141183460469231731687303715884105728i128), + 170141183460469231731687303715884105727i128 + ); std::hint::black_box(std::hint::black_box(7571400400375753350092698930310845914i128) * 10); assert!(0i128.checked_div(2i128).is_some()); @@ -113,7 +116,9 @@ fn main() { Box::pin(move |mut _task_context| { yield (); - }).as_mut().resume(0); + }) + .as_mut() + .resume(0); #[derive(Copy, Clone)] enum Nums { @@ -148,12 +153,20 @@ fn main() { enum Never {} } + + foo(I64X2(0, 0)); } fn panic(_: u128) { panic!(); } +#[repr(simd)] +struct I64X2(i64, i64); + +#[allow(improper_ctypes_definitions)] +extern "C" fn foo(_a: I64X2) {} + #[cfg(target_arch = "x86_64")] #[target_feature(enable = "sse2")] unsafe fn test_simd() { @@ -168,7 +181,10 @@ unsafe fn test_simd() { let (zero0, zero1) = std::mem::transmute::<_, (u64, u64)>(x); assert_eq!((zero0, zero1), (0, 0)); assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]); - assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_eq), [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff]); + assert_eq!( + std::mem::transmute::<_, [u16; 8]>(cmp_eq), + [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff] + ); assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_lt), [0, 0, 0, 0, 0, 0, 0, 0]); test_mm_slli_si128(); @@ -182,6 +198,7 @@ unsafe fn test_simd() { test_mm_extract_epi8(); test_mm_insert_epi16(); + #[rustfmt::skip] let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))); assert_eq!(mask1, 1); } @@ -343,7 +360,7 @@ fn test_checked_mul() { #[derive(PartialEq)] enum LoopState { Continue(()), - Break(()) + Break(()), } pub enum Instruction { diff --git a/example/subslice-patterns-const-eval.rs b/example/subslice-patterns-const-eval.rs index 2cb84786f56..3c878916663 100644 --- a/example/subslice-patterns-const-eval.rs +++ b/example/subslice-patterns-const-eval.rs @@ -19,7 +19,9 @@ macro_rules! n { // This macro has an unused variable so that it can be repeated base on the // number of times a repeated variable (`$e` in `z`) occurs. macro_rules! zed { - ($e:expr) => { Z } + ($e:expr) => { + Z + }; } macro_rules! z { @@ -32,12 +34,14 @@ macro_rules! z { macro_rules! compare_evaluation { ($e:expr, $t:ty $(,)?) => {{ const CONST_EVAL: $t = $e; - const fn const_eval() -> $t { $e } + const fn const_eval() -> $t { + $e + } static CONST_EVAL2: $t = const_eval(); let runtime_eval = $e; assert_eq!(CONST_EVAL, runtime_eval); assert_eq!(CONST_EVAL2, runtime_eval); - }} + }}; } // Repeat `$test`, substituting the given macro variables with the given @@ -65,6 +69,7 @@ macro_rules! repeat { } } +#[rustfmt::skip] fn main() { repeat! { ($arr $Ty); n, N; z, Z: diff --git a/rust-toolchain b/rust-toolchain index 2236a6ca155..59ad80c3207 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-03-15" +channel = "nightly-2023-04-29" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/scripts/cargo-clif.rs b/scripts/cargo-clif.rs index 939a1f1ca59..e2db7d03a9d 100644 --- a/scripts/cargo-clif.rs +++ b/scripts/cargo-clif.rs @@ -64,7 +64,7 @@ fn main() { }; #[cfg(unix)] - Command::new("cargo").args(args).exec(); + panic!("Failed to spawn cargo: {}", Command::new("cargo").args(args).exec()); #[cfg(not(unix))] std::process::exit( diff --git a/scripts/rustc-clif.rs b/scripts/rustc-clif.rs index b9bba7f2e08..ab496a4a684 100644 --- a/scripts/rustc-clif.rs +++ b/scripts/rustc-clif.rs @@ -15,22 +15,24 @@ fn main() { env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX, ); - let mut args = std::env::args_os().skip(1).collect::>(); + let passed_args = std::env::args_os().skip(1).collect::>(); + let mut args = vec![]; args.push(OsString::from("-Cpanic=abort")); args.push(OsString::from("-Zpanic-abort-tests")); let mut codegen_backend_arg = OsString::from("-Zcodegen-backend="); codegen_backend_arg.push(cg_clif_dylib_path); args.push(codegen_backend_arg); - if !args.contains(&OsString::from("--sysroot")) { + if !passed_args.contains(&OsString::from("--sysroot")) { args.push(OsString::from("--sysroot")); args.push(OsString::from(sysroot.to_str().unwrap())); } + args.extend(passed_args); // Ensure that the right toolchain is used env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); #[cfg(unix)] - Command::new("rustc").args(args).exec(); + panic!("Failed to spawn rustc: {}", Command::new("rustc").args(args).exec()); #[cfg(not(unix))] std::process::exit( diff --git a/scripts/rustdoc-clif.rs b/scripts/rustdoc-clif.rs index 167631eaf7e..545844446c5 100644 --- a/scripts/rustdoc-clif.rs +++ b/scripts/rustdoc-clif.rs @@ -15,22 +15,24 @@ fn main() { env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX, ); - let mut args = std::env::args_os().skip(1).collect::>(); + let passed_args = std::env::args_os().skip(1).collect::>(); + let mut args = vec![]; args.push(OsString::from("-Cpanic=abort")); args.push(OsString::from("-Zpanic-abort-tests")); let mut codegen_backend_arg = OsString::from("-Zcodegen-backend="); codegen_backend_arg.push(cg_clif_dylib_path); args.push(codegen_backend_arg); - if !args.contains(&OsString::from("--sysroot")) { + if !passed_args.contains(&OsString::from("--sysroot")) { args.push(OsString::from("--sysroot")); args.push(OsString::from(sysroot.to_str().unwrap())); } + args.extend(passed_args); // Ensure that the right toolchain is used env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); #[cfg(unix)] - Command::new("rustdoc").args(args).exec(); + panic!("Failed to spawn rustdoc: {}", Command::new("rustdoc").args(args).exec()); #[cfg(not(unix))] std::process::exit( diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 20dcb4cf34d..1329d3ea076 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -10,7 +10,8 @@ pushd rust command -v rg >/dev/null 2>&1 || cargo install ripgrep -rm -r tests/ui/{extern/,unsized-locals/,lto/,linkage*} || true +# FIXME add needs-asm-support to all tests in tests/ui/asm +rm -r tests/ui/{unsized-locals/,lto/,linkage*} || true for test in $(rg --files-with-matches "lto|// needs-asm-support|// needs-unwind" tests/{codegen-units,ui,incremental}); do rm $test done @@ -27,13 +28,24 @@ rm tests/ui/parser/unclosed-delimiter-in-dep.rs # submodule contains //~ERROR # ================ # requires stack unwinding +# FIXME add needs-unwind to these tests rm tests/incremental/change_crate_dep_kind.rs rm tests/incremental/issue-80691-bad-eval-cache.rs # -Cpanic=abort causes abort instead of exit(101) +rm -r tests/run-make/c-unwind-abi-catch-lib-panic +rm -r tests/run-make/c-unwind-abi-catch-panic +rm -r tests/run-make/debug-assertions +rm -r tests/run-make/foreign-double-unwind +rm -r tests/run-make/foreign-exceptions +rm -r tests/run-make/foreign-rust-exceptions +rm -r tests/run-make/libtest-json +rm -r tests/run-make/static-unwinding # requires compiling with -Cpanic=unwind rm -r tests/ui/macros/rfc-2011-nicer-assert-messages/ rm -r tests/run-make/test-benches rm tests/ui/test-attrs/test-type.rs +rm -r tests/run-make/const_fn_mir +rm -r tests/run-make/intrinsic-unreachable # vendor intrinsics rm tests/ui/sse2.rs # cpuid not supported, so sse2 not detected @@ -49,6 +61,7 @@ rm tests/incremental/hashes/statics.rs # same # variadic arguments rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs rm tests/ui/abi/variadic-ffi.rs # requires callee side vararg support +rm -r tests/run-make/c-link-to-rust-va-list-fn # requires callee side vararg support # unsized locals rm -r tests/run-pass-valgrind/unsized-locals @@ -59,6 +72,19 @@ rm tests/ui/target-feature/missing-plusminus.rs # error not implemented rm tests/ui/fn/dyn-fn-alignment.rs # wants a 256 byte alignment rm -r tests/run-make/emit-named-files # requires full --emit support rm -r tests/run-make/repr128-dwarf # debuginfo test +rm -r tests/run-make/split-debuginfo # same +rm -r tests/run-make/symbols-include-type-name # --emit=asm not supported +rm -r tests/run-make/target-specs # i686 not supported by Cranelift +rm -r tests/run-make/mismatching-target-triples # same +rm -r tests/run-make/use-extern-for-plugins # same + +# requires LTO +rm -r tests/run-make/cdylib +rm -r tests/run-make/issue-14500 +rm -r tests/run-make/issue-64153 +rm -r tests/run-make/codegen-options-parsing +rm -r tests/run-make/lto-* +rm -r tests/run-make/reproducible-build-2 # optimization tests # ================== @@ -70,7 +96,14 @@ rm -r tests/run-make/fmt-write-bloat/ # tests an optimization # backend specific tests # ====================== rm tests/incremental/thinlto/cgu_invalidated_when_import_{added,removed}.rs # requires LLVM +rm -r tests/run-make/cross-lang-lto # same +rm -r tests/run-make/issue-7349 # same +rm -r tests/run-make/sepcomp-inlining # same +rm -r tests/run-make/sepcomp-separate # same +rm -r tests/run-make/sepcomp-cci-copies # same +rm -r tests/run-make/volatile-intrinsics # same rm tests/ui/abi/stack-protector.rs # requires stack protector support +rm -r tests/run-make/emit-stack-sizes # requires support for -Z emit-stack-sizes # giving different but possibly correct results # ============================================= @@ -95,13 +128,12 @@ rm tests/ui/proc-macro/no-missing-docs.rs # same rm tests/ui/rust-2018/proc-macro-crate-in-paths.rs # same rm tests/ui/proc-macro/allowed-signatures.rs # same +# rustdoc-clif passes extra args, suppressing the help message when no args are passed +rm -r tests/run-make/issue-88756-default-output + # doesn't work due to the way the rustc test suite is invoked. # should work when using ./x.py test the way it is intended # ============================================================ -rm -r tests/run-make/emit-shared-files # requires the rustdoc executable in dist/bin/ -rm -r tests/run-make/unstable-flag-required # same -rm -r tests/run-make/rustdoc-* # same -rm -r tests/run-make/issue-88756-default-output # same rm -r tests/run-make/remap-path-prefix-dwarf # requires llvm-dwarfdump rm -r tests/ui/consts/missing_span_in_backtrace.rs # expects sysroot source to be elsewhere @@ -112,17 +144,41 @@ rm tests/incremental/spike-neg2.rs # same rm tests/ui/simd/intrinsic/generic-reduction-pass.rs # simd_reduce_add_unordered doesn't accept an accumulator for integer vectors -rm tests/ui/simd/intrinsic/generic-as.rs # crash when accessing vector type field (#1318) rm tests/ui/simd/simd-bitmask.rs # crash +rm -r tests/run-make/issue-51671 # wrong filename given in case of --emit=obj +rm -r tests/run-make/issue-30063 # same +rm -r tests/run-make/multiple-emits # same +rm -r tests/run-make/output-type-permutations # same +rm -r tests/run-make/used # same + # bugs in the test suite # ====================== rm tests/ui/backtrace.rs # TODO warning -rm tests/ui/simple_global_asm.rs # TODO add needs-asm-support rm tests/ui/process/nofile-limit.rs # TODO some AArch64 linking issue rm tests/ui/stdio-is-blocking.rs # really slow with unoptimized libstd +cp ../dist/bin/rustdoc-clif ../dist/bin/rustdoc # some tests expect bin/rustdoc to exist + +# prevent $(RUSTDOC) from picking up the sysroot built by x.py. It conflicts with the one used by +# rustdoc-clif +cat <) { @@ -91,35 +89,7 @@ pub(super) fn add_local_place_comments<'tcx>( largest_niche: _, } = layout.0.0; - let (kind, extra) = match *place.inner() { - CPlaceInner::Var(place_local, var) => { - assert_eq!(local, place_local); - ("ssa", Cow::Owned(format!(",var={}", var.index()))) - } - CPlaceInner::VarPair(place_local, var1, var2) => { - assert_eq!(local, place_local); - ("ssa", Cow::Owned(format!("var=({}, {})", var1.index(), var2.index()))) - } - CPlaceInner::VarLane(_local, _var, _lane) => unreachable!(), - CPlaceInner::Addr(ptr, meta) => { - let meta = if let Some(meta) = meta { - Cow::Owned(format!("meta={}", meta)) - } else { - Cow::Borrowed("") - }; - match ptr.debug_base_and_offset() { - (crate::pointer::PointerBase::Addr(addr), offset) => { - ("reuse", format!("storage={}{}{}", addr, offset, meta).into()) - } - (crate::pointer::PointerBase::Stack(stack_slot), offset) => { - ("stack", format!("storage={}{}{}", stack_slot, offset, meta).into()) - } - (crate::pointer::PointerBase::Dangling(align), offset) => { - ("zst", format!("align={},offset={}", align.bytes(), offset).into()) - } - } - } - }; + let (kind, extra) = place.debug_comment(); fx.add_global_comment(format!( "{:<5} {:5} {:30} {:4}b {}, {}{}{}", diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 0b4d4ecf2e4..e533afcfaa9 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -605,9 +605,9 @@ pub(crate) fn codegen_drop<'tcx>( // | ... | // \-------/ // - let (ptr, vtable) = drop_place.to_ptr_maybe_unsized(); + let (ptr, vtable) = drop_place.to_ptr_unsized(); let ptr = ptr.get_addr(fx); - let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable.unwrap()); + let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable); // FIXME(eddyb) perhaps move some of this logic into // `Instance::resolve_drop_in_place`? diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index e5ad31eb948..d847e524f8c 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -84,7 +84,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { attrs )], Abi::Vector { .. } => { - let vector_ty = crate::intrinsics::clif_vector_type(tcx, self.layout).unwrap(); + let vector_ty = crate::intrinsics::clif_vector_type(tcx, self.layout); smallvec![AbiParam::new(vector_ty)] } _ => unreachable!("{:?}", self.layout.abi), @@ -135,7 +135,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { (None, vec![AbiParam::new(scalar_to_clif_type(tcx, scalar))]) } Abi::Vector { .. } => { - let vector_ty = crate::intrinsics::clif_vector_type(tcx, self.layout).unwrap(); + let vector_ty = crate::intrinsics::clif_vector_type(tcx, self.layout); (None, vec![AbiParam::new(vector_ty)]) } _ => unreachable!("{:?}", self.layout.abi), diff --git a/src/abi/returning.rs b/src/abi/returning.rs index bd055216e36..14e54d5ee38 100644 --- a/src/abi/returning.rs +++ b/src/abi/returning.rs @@ -63,11 +63,11 @@ pub(super) fn codegen_with_call_return_arg<'tcx>( let (ret_temp_place, return_ptr) = match ret_arg_abi.mode { PassMode::Ignore => (None, None), PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => { - if matches!(ret_place.inner(), CPlaceInner::Addr(_, None)) { + if let Some(ret_ptr) = ret_place.try_to_ptr() { // This is an optimization to prevent unnecessary copies of the return value when // the return place is already a memory place as opposed to a register. // This match arm can be safely removed. - (None, Some(ret_place.to_ptr().get_addr(fx))) + (None, Some(ret_ptr.get_addr(fx))) } else { let place = CPlace::new_stack_slot(fx, ret_arg_abi.layout); (Some(place), Some(place.to_ptr().get_addr(fx))) diff --git a/src/base.rs b/src/base.rs index c181c73e4be..a259a4f30b2 100644 --- a/src/base.rs +++ b/src/base.rs @@ -141,16 +141,6 @@ pub(crate) fn compile_fn( context.clear(); context.func = codegened_func.func; - // If the return block is not reachable, then the SSA builder may have inserted an `iconst.i128` - // instruction, which doesn't have an encoding. - context.compute_cfg(); - context.compute_domtree(); - context.eliminate_unreachable_code(module.isa()).unwrap(); - context.dce(module.isa()).unwrap(); - // Some Cranelift optimizations expect the domtree to not yet be computed and as such don't - // invalidate it when it would change. - context.domtree.clear(); - #[cfg(any())] // This is never true let _clif_guard = { use std::fmt::Write; @@ -182,27 +172,6 @@ pub(crate) fn compile_fn( cx.profiler.generic_activity("define function").run(|| { context.want_disasm = cx.should_write_ir; module.define_function(codegened_func.func_id, context).unwrap(); - - if cx.profiler.enabled() { - let mut recording_args = false; - cx.profiler - .generic_activity_with_arg_recorder( - "define function (clif pass timings)", - |recorder| { - let pass_times = cranelift_codegen::timing::take_current(); - // Replace newlines with | as measureme doesn't allow control characters like - // newlines inside strings. - recorder.record_arg(format!("{}", pass_times).replace('\n', " | ")); - recording_args = true; - }, - ) - .run(|| { - if recording_args { - // Wait a tiny bit to ensure chrome's profiler doesn't hide the event - std::thread::sleep(std::time::Duration::from_nanos(2)) - } - }); - } }); if cx.should_write_ir { @@ -216,7 +185,7 @@ pub(crate) fn compile_fn( &clif_comments, ); - if let Some(disasm) = &context.compiled_code().unwrap().disasm { + if let Some(disasm) = &context.compiled_code().unwrap().vcode { crate::pretty_clif::write_ir_file( &cx.output_filenames, &format!("{}.vcode", codegened_func.symbol_name), @@ -524,13 +493,14 @@ fn codegen_stmt<'tcx>( fx.set_debug_loc(stmt.source_info); - #[cfg(any())] // This is never true match &stmt.kind { StatementKind::StorageLive(..) | StatementKind::StorageDead(..) => {} // Those are not very useful _ => { if fx.clif_comments.enabled() { let inst = fx.bcx.func.layout.last_inst(cur_block).unwrap(); - fx.add_comment(inst, format!("{:?}", stmt)); + with_no_trimmed_paths!({ + fx.add_comment(inst, format!("{:?}", stmt)); + }); } } } @@ -715,11 +685,11 @@ fn codegen_stmt<'tcx>( } Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), ref operand, _to_ty) => { let operand = codegen_operand(fx, operand); - operand.unsize_value(fx, lval); + crate::unsize::coerce_unsized_into(fx, operand, lval); } Rvalue::Cast(CastKind::DynStar, ref operand, _) => { let operand = codegen_operand(fx, operand); - operand.coerce_dyn_star(fx, lval); + crate::unsize::coerce_dyn_star(fx, operand, lval); } Rvalue::Cast(CastKind::Transmute, ref operand, _to_ty) => { let operand = codegen_operand(fx, operand); @@ -791,7 +761,10 @@ fn codegen_stmt<'tcx>( layout.offset_of_subfield(fx, fields.iter().map(|f| f.index())).bytes() } }; - let val = CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), val.into()); + let val = CValue::by_val( + fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(val).unwrap()), + fx.layout_of(fx.tcx.types.usize), + ); lval.write_cvalue(fx, val); } Rvalue::Aggregate(ref kind, ref operands) => { @@ -866,9 +839,7 @@ fn codegen_array_len<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, place: CPlace<'tcx let len = fx.monomorphize(len).eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64; fx.bcx.ins().iconst(fx.pointer_type, len) } - ty::Slice(_elem_ty) => { - place.to_ptr_maybe_unsized().1.expect("Length metadata for slice place") - } + ty::Slice(_elem_ty) => place.to_ptr_unsized().1, _ => bug!("Rvalue::Len({:?})", place), } } @@ -922,8 +893,7 @@ pub(crate) fn codegen_place<'tcx>( ty::Slice(elem_ty) => { assert!(from_end, "slice subslices should be `from_end`"); let elem_layout = fx.layout_of(*elem_ty); - let (ptr, len) = cplace.to_ptr_maybe_unsized(); - let len = len.unwrap(); + let (ptr, len) = cplace.to_ptr_unsized(); cplace = CPlace::for_ptr_with_extra( ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * (from as i64)), fx.bcx.ins().iadd_imm(len, -(from as i64 + to as i64)), diff --git a/src/cast.rs b/src/cast.rs index 032d1151041..6bf3a866ba4 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -103,7 +103,7 @@ pub(crate) fn clif_int_or_float_cast( vec![AbiParam::new(types::I64X2)], &[from], )[0]; - // FIXME use bitcast instead of store to get from i64x2 to i128 + // FIXME(bytecodealliance/wasmtime#6104) use bitcast instead of store to get from i64x2 to i128 let stack_slot = fx.bcx.create_sized_stack_slot(StackSlotData { kind: StackSlotKind::ExplicitSlot, size: 16, diff --git a/src/codegen_i128.rs b/src/codegen_i128.rs index f674ce776a6..f751d8c179d 100644 --- a/src/codegen_i128.rs +++ b/src/codegen_i128.rs @@ -7,7 +7,6 @@ use crate::prelude::*; pub(crate) fn maybe_codegen<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, bin_op: BinOp, - checked: bool, lhs: CValue<'tcx>, rhs: CValue<'tcx>, ) -> Option> { @@ -22,47 +21,97 @@ pub(crate) fn maybe_codegen<'tcx>( let is_signed = type_sign(lhs.layout().ty); match bin_op { - BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => { - assert!(!checked); - None + BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => None, + BinOp::Add | BinOp::Sub => None, + BinOp::Mul => { + let args = [lhs.load_scalar(fx), rhs.load_scalar(fx)]; + let ret_val = fx.lib_call( + "__multi3", + vec![AbiParam::new(types::I128), AbiParam::new(types::I128)], + vec![AbiParam::new(types::I128)], + &args, + )[0]; + Some(CValue::by_val( + ret_val, + fx.layout_of(if is_signed { fx.tcx.types.i128 } else { fx.tcx.types.u128 }), + )) } - BinOp::Add | BinOp::Sub if !checked => None, - BinOp::Mul if !checked || is_signed => { - if !checked { + BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"), + BinOp::Div | BinOp::Rem => { + let name = match (bin_op, is_signed) { + (BinOp::Div, false) => "__udivti3", + (BinOp::Div, true) => "__divti3", + (BinOp::Rem, false) => "__umodti3", + (BinOp::Rem, true) => "__modti3", + _ => unreachable!(), + }; + if fx.tcx.sess.target.is_like_windows { + let args = [lhs.load_scalar(fx), rhs.load_scalar(fx)]; + let ret = fx.lib_call( + name, + vec![AbiParam::new(types::I128), AbiParam::new(types::I128)], + vec![AbiParam::new(types::I64X2)], + &args, + )[0]; + // FIXME(bytecodealliance/wasmtime#6104) use bitcast instead of store to get from i64x2 to i128 + let ret_place = CPlace::new_stack_slot(fx, lhs.layout()); + ret_place.to_ptr().store(fx, ret, MemFlags::trusted()); + Some(ret_place.to_cvalue(fx)) + } else { let args = [lhs.load_scalar(fx), rhs.load_scalar(fx)]; let ret_val = fx.lib_call( - "__multi3", + name, vec![AbiParam::new(types::I128), AbiParam::new(types::I128)], vec![AbiParam::new(types::I128)], &args, )[0]; - Some(CValue::by_val( - ret_val, - fx.layout_of(if is_signed { fx.tcx.types.i128 } else { fx.tcx.types.u128 }), - )) - } else { - let out_ty = fx.tcx.mk_tup(&[lhs.layout().ty, fx.tcx.types.bool]); - let oflow = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32)); - let lhs = lhs.load_scalar(fx); - let rhs = rhs.load_scalar(fx); - let oflow_ptr = oflow.to_ptr().get_addr(fx); - let res = fx.lib_call_unadjusted( - "__muloti4", - vec![ - AbiParam::new(types::I128), - AbiParam::new(types::I128), - AbiParam::new(fx.pointer_type), - ], - vec![AbiParam::new(types::I128)], - &[lhs, rhs, oflow_ptr], - )[0]; - let oflow = oflow.to_cvalue(fx).load_scalar(fx); - let oflow = fx.bcx.ins().ireduce(types::I8, oflow); - Some(CValue::by_val_pair(res, oflow, fx.layout_of(out_ty))) + Some(CValue::by_val(ret_val, lhs.layout())) } } + BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => None, + BinOp::Shl | BinOp::Shr => None, + } +} + +pub(crate) fn maybe_codegen_checked<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + bin_op: BinOp, + lhs: CValue<'tcx>, + rhs: CValue<'tcx>, +) -> Option> { + if lhs.layout().ty != fx.tcx.types.u128 + && lhs.layout().ty != fx.tcx.types.i128 + && rhs.layout().ty != fx.tcx.types.u128 + && rhs.layout().ty != fx.tcx.types.i128 + { + return None; + } + + let is_signed = type_sign(lhs.layout().ty); + + match bin_op { + BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => unreachable!(), + BinOp::Mul if is_signed => { + let out_ty = fx.tcx.mk_tup(&[lhs.layout().ty, fx.tcx.types.bool]); + let oflow = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32)); + let lhs = lhs.load_scalar(fx); + let rhs = rhs.load_scalar(fx); + let oflow_ptr = oflow.to_ptr().get_addr(fx); + let res = fx.lib_call_unadjusted( + "__muloti4", + vec![ + AbiParam::new(types::I128), + AbiParam::new(types::I128), + AbiParam::new(fx.pointer_type), + ], + vec![AbiParam::new(types::I128)], + &[lhs, rhs, oflow_ptr], + )[0]; + let oflow = oflow.to_cvalue(fx).load_scalar(fx); + let oflow = fx.bcx.ins().ireduce(types::I8, oflow); + Some(CValue::by_val_pair(res, oflow, fx.layout_of(out_ty))) + } BinOp::Add | BinOp::Sub | BinOp::Mul => { - assert!(checked); let out_ty = fx.tcx.mk_tup(&[lhs.layout().ty, fx.tcx.types.bool]); let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty)); let param_types = vec![ @@ -83,42 +132,8 @@ pub(crate) fn maybe_codegen<'tcx>( Some(out_place.to_cvalue(fx)) } BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"), - BinOp::Div | BinOp::Rem => { - assert!(!checked); - let name = match (bin_op, is_signed) { - (BinOp::Div, false) => "__udivti3", - (BinOp::Div, true) => "__divti3", - (BinOp::Rem, false) => "__umodti3", - (BinOp::Rem, true) => "__modti3", - _ => unreachable!(), - }; - if fx.tcx.sess.target.is_like_windows { - let args = [lhs.load_scalar(fx), rhs.load_scalar(fx)]; - let ret = fx.lib_call( - name, - vec![AbiParam::new(types::I128), AbiParam::new(types::I128)], - vec![AbiParam::new(types::I64X2)], - &args, - )[0]; - // FIXME use bitcast instead of store to get from i64x2 to i128 - let ret_place = CPlace::new_stack_slot(fx, lhs.layout()); - ret_place.to_ptr().store(fx, ret, MemFlags::trusted()); - Some(ret_place.to_cvalue(fx)) - } else { - let args = [lhs.load_scalar(fx), rhs.load_scalar(fx)]; - let ret_val = fx.lib_call( - name, - vec![AbiParam::new(types::I128), AbiParam::new(types::I128)], - vec![AbiParam::new(types::I128)], - &args, - )[0]; - Some(CValue::by_val(ret_val, lhs.layout())) - } - } - BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => { - assert!(!checked); - None - } - BinOp::Shl | BinOp::Shr => None, + BinOp::Div | BinOp::Rem => unreachable!(), + BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => unreachable!(), + BinOp::Shl | BinOp::Shr => unreachable!(), } } diff --git a/src/common.rs b/src/common.rs index 528b35283d7..30f4cf4473c 100644 --- a/src/common.rs +++ b/src/common.rs @@ -72,19 +72,6 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option { - let (element, count) = match &tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().abi - { - Abi::Vector { element, count } => (*element, *count), - _ => unreachable!(), - }; - - match scalar_to_clif_type(tcx, element).by(u32::try_from(count).unwrap()) { - // Cranelift currently only implements icmp for 128bit vectors. - Some(vector_ty) if vector_ty.bits() == 128 => vector_ty, - _ => return None, - } - } ty::Param(_) => bug!("ty param {:?}", ty), _ => return None, }) @@ -96,12 +83,7 @@ fn clif_pair_type_from_ty<'tcx>( ) -> Option<(types::Type, types::Type)> { Some(match ty.kind() { ty::Tuple(types) if types.len() == 2 => { - let a = clif_type_from_ty(tcx, types[0])?; - let b = clif_type_from_ty(tcx, types[1])?; - if a.is_vector() || b.is_vector() { - return None; - } - (a, b) + (clif_type_from_ty(tcx, types[0])?, clif_type_from_ty(tcx, types[1])?) } ty::RawPtr(TypeAndMut { ty: pointee_ty, mutbl: _ }) | ty::Ref(_, pointee_ty, _) => { if has_ptr_meta(tcx, *pointee_ty) { @@ -431,7 +413,11 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { // Note: must be kept in sync with get_caller_location from cg_ssa pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> { - let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| { + let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, mut span: Span| { + // Remove `Inlined` marks as they pollute `expansion_cause`. + while span.is_inlined() { + span.remove_mark(); + } let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo()); let const_loc = fx.tcx.const_caller_location(( diff --git a/src/concurrency_limiter.rs b/src/concurrency_limiter.rs index 203219a8a75..54df04f8c2c 100644 --- a/src/concurrency_limiter.rs +++ b/src/concurrency_limiter.rs @@ -25,8 +25,18 @@ impl ConcurrencyLimiter { .clone() .into_helper_thread(move |token| { let mut state = state_helper.lock().unwrap(); - state.add_new_token(token.unwrap()); - available_token_condvar_helper.notify_one(); + match token { + Ok(token) => { + state.add_new_token(token); + available_token_condvar_helper.notify_one(); + } + Err(err) => { + state.poison(format!("failed to acquire jobserver token: {}", err)); + // Notify all threads waiting for a token to give them a chance to + // gracefully exit. + available_token_condvar_helper.notify_all(); + } + } }) .unwrap(); ConcurrencyLimiter { @@ -37,16 +47,31 @@ impl ConcurrencyLimiter { } } - pub(super) fn acquire(&mut self) -> ConcurrencyLimiterToken { + pub(super) fn acquire(&mut self, handler: &rustc_errors::Handler) -> ConcurrencyLimiterToken { let mut state = self.state.lock().unwrap(); loop { state.assert_invariants(); - if state.try_start_job() { - return ConcurrencyLimiterToken { - state: self.state.clone(), - available_token_condvar: self.available_token_condvar.clone(), - }; + match state.try_start_job() { + Ok(true) => { + return ConcurrencyLimiterToken { + state: self.state.clone(), + available_token_condvar: self.available_token_condvar.clone(), + }; + } + Ok(false) => {} + Err(err) => { + // An error happened when acquiring the token. Raise it as fatal error. + // Make sure to drop the mutex guard first to prevent poisoning the mutex. + drop(state); + if let Some(err) = err { + handler.fatal(&err).raise(); + } else { + // The error was already emitted, but compilation continued. Raise a silent + // fatal error. + rustc_errors::FatalError.raise(); + } + } } self.helper_thread.as_mut().unwrap().request_token(); @@ -100,13 +125,22 @@ mod state { pending_jobs: usize, active_jobs: usize, + poisoned: bool, + stored_error: Option, + // None is used to represent the implicit token, Some to represent explicit tokens tokens: Vec>, } impl ConcurrencyLimiterState { pub(super) fn new(pending_jobs: usize) -> Self { - ConcurrencyLimiterState { pending_jobs, active_jobs: 0, tokens: vec![None] } + ConcurrencyLimiterState { + pending_jobs, + active_jobs: 0, + poisoned: false, + stored_error: None, + tokens: vec![None], + } } pub(super) fn assert_invariants(&self) { @@ -127,14 +161,18 @@ mod state { self.drop_excess_capacity(); } - pub(super) fn try_start_job(&mut self) -> bool { + pub(super) fn try_start_job(&mut self) -> Result> { + if self.poisoned { + return Err(self.stored_error.take()); + } + if self.active_jobs < self.tokens.len() { // Using existing token self.job_started(); - return true; + return Ok(true); } - false + Ok(false) } pub(super) fn job_started(&mut self) { @@ -161,6 +199,11 @@ mod state { self.assert_invariants(); } + pub(super) fn poison(&mut self, error: String) { + self.poisoned = true; + self.stored_error = Some(error); + } + fn drop_excess_capacity(&mut self) { self.assert_invariants(); diff --git a/src/constant.rs b/src/constant.rs index aacf37bb5b7..bf5d29c16f6 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -159,6 +159,8 @@ pub(crate) fn codegen_const_value<'tcx>( _ => unreachable!(), }; + // FIXME avoid this extra copy to the stack and directly write to the final + // destination let place = CPlace::new_stack_slot(fx, layout); place.to_ptr().store(fx, val, MemFlags::trusted()); place.to_cvalue(fx) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 3e2e2af9688..0e6c6ad95aa 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -324,6 +324,10 @@ fn module_codegen( OngoingModuleCodegen::Async(std::thread::spawn(move || { cx.profiler.clone().verbose_generic_activity_with_arg("compile functions", &*cgu_name).run( || { + cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler( + cx.profiler.clone(), + ))); + let mut cached_context = Context::new(); for codegened_func in codegened_functions { crate::base::compile_fn( @@ -407,7 +411,7 @@ pub(crate) fn run_aot( backend_config.clone(), global_asm_config.clone(), cgu.name(), - concurrency_limiter.acquire(), + concurrency_limiter.acquire(tcx.sess.diagnostic()), ), module_codegen, Some(rustc_middle::dep_graph::hash_result), diff --git a/src/driver/jit.rs b/src/driver/jit.rs index f6a48e3257b..3118105a4e2 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -224,6 +224,10 @@ pub(crate) fn codegen_and_compile_fn<'tcx>( module: &mut dyn Module, instance: Instance<'tcx>, ) { + cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler( + cx.profiler.clone(), + ))); + tcx.prof.generic_activity("codegen and compile fn").run(|| { let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name)); diff --git a/src/driver/mod.rs b/src/driver/mod.rs index d09d3a52975..5c52c9c18ad 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -4,6 +4,7 @@ //! [`codegen_fn`]: crate::base::codegen_fn //! [`codegen_static`]: crate::constant::codegen_static +use rustc_data_structures::profiling::SelfProfilerRef; use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility}; use crate::prelude::*; @@ -39,3 +40,31 @@ fn predefine_mono_items<'tcx>( } }); } + +struct MeasuremeProfiler(SelfProfilerRef); + +struct TimingGuard { + profiler: std::mem::ManuallyDrop, + inner: Option>, +} + +impl Drop for TimingGuard { + fn drop(&mut self) { + self.inner.take(); + unsafe { + std::mem::ManuallyDrop::drop(&mut self.profiler); + } + } +} + +impl cranelift_codegen::timing::Profiler for MeasuremeProfiler { + fn start_pass(&self, pass: cranelift_codegen::timing::Pass) -> Box { + let mut timing_guard = + TimingGuard { profiler: std::mem::ManuallyDrop::new(self.0.clone()), inner: None }; + timing_guard.inner = Some( + unsafe { &*(&*timing_guard.profiler as &SelfProfilerRef as *const SelfProfilerRef) } + .generic_activity(pass.description()), + ); + Box::new(timing_guard) + } +} diff --git a/src/global_asm.rs b/src/global_asm.rs index a74f8ffa23d..63a1f6959dd 100644 --- a/src/global_asm.rs +++ b/src/global_asm.rs @@ -104,7 +104,6 @@ pub(crate) fn compile_global_asm( return Ok(None); } - // FIXME fix linker error on macOS if cfg!(not(feature = "inline_asm")) { return Err( "asm! and global_asm! support is disabled while compiling rustc_codegen_cranelift" diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 90b36c61114..539f8c103db 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -51,17 +51,13 @@ fn report_atomic_type_validation_error<'tcx>( fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } -pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Option { +pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Type { let (element, count) = match layout.abi { Abi::Vector { element, count } => (element, count), _ => unreachable!(), }; - match scalar_to_clif_type(tcx, element).by(u32::try_from(count).unwrap()) { - // Cranelift currently only implements icmp for 128bit vectors. - Some(vector_ty) if vector_ty.bits() == 128 => Some(vector_ty), - _ => None, - } + scalar_to_clif_type(tcx, element).by(u32::try_from(count).unwrap()).unwrap() } fn simd_for_each_lane<'tcx>( @@ -1107,8 +1103,8 @@ fn codegen_regular_intrinsic_call<'tcx>( fx.bcx.ins().call_indirect(f_sig, f, &[data]); - let layout = ret.layout(); - let ret_val = CValue::const_val(fx, layout, ty::ScalarInt::null(layout.size)); + let layout = fx.layout_of(fx.tcx.types.i32); + let ret_val = CValue::by_val(fx.bcx.ins().iconst(types::I32, 0), layout); ret.write_cvalue(fx, ret_val); } diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 6f54a8d49c8..264b578c168 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -253,7 +253,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( } ret.write_cvalue(fx, base); - let ret_lane = ret.place_field(fx, FieldIdx::new(idx.try_into().unwrap())); + let ret_lane = ret.place_lane(fx, idx.try_into().unwrap()); ret_lane.write_cvalue(fx, val); } diff --git a/src/lib.rs b/src/lib.rs index 74d9b72b90c..f0b399ae280 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,7 +110,7 @@ mod prelude { pub(crate) use crate::common::*; pub(crate) use crate::debuginfo::{DebugContext, UnwindContext}; pub(crate) use crate::pointer::Pointer; - pub(crate) use crate::value_and_place::{CPlace, CPlaceInner, CValue}; + pub(crate) use crate::value_and_place::{CPlace, CValue}; } struct PrintOnPanic String>(F); diff --git a/src/num.rs b/src/num.rs index 1357b7be1e0..ba53e01c7a2 100644 --- a/src/num.rs +++ b/src/num.rs @@ -118,7 +118,7 @@ pub(crate) fn codegen_int_binop<'tcx>( ); } - if let Some(res) = crate::codegen_i128::maybe_codegen(fx, bin_op, false, in_lhs, in_rhs) { + if let Some(res) = crate::codegen_i128::maybe_codegen(fx, bin_op, in_lhs, in_rhs) { return res; } @@ -173,7 +173,7 @@ pub(crate) fn codegen_checked_int_binop<'tcx>( let lhs = in_lhs.load_scalar(fx); let rhs = in_rhs.load_scalar(fx); - if let Some(res) = crate::codegen_i128::maybe_codegen(fx, bin_op, true, in_lhs, in_rhs) { + if let Some(res) = crate::codegen_i128::maybe_codegen_checked(fx, bin_op, in_lhs, in_rhs) { return res; } diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index e0a081c9d49..27e21183c55 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -7,48 +7,51 @@ //! test compile //! target x86_64 //! -//! function u0:0(i64, i64, i64) system_v { -//! ; symbol _ZN119_$LT$example..IsNotEmpty$u20$as$u20$mini_core..FnOnce$LT$$LP$$RF$$u27$a$u20$$RF$$u27$b$u20$$u5b$u16$u5d$$C$$RP$$GT$$GT$9call_once17he85059d5e6a760a0E -//! ; instance Instance { def: Item(DefId(0/0:29 ~ example[8787]::{{impl}}[0]::call_once[0])), substs: [ReErased, ReErased] } -//! ; sig ([IsNotEmpty, (&&[u16],)]; c_variadic: false)->(u8, u8) +//! function u0:22(i64) -> i8, i8 system_v { +//! ; symbol _ZN97_$LT$example..IsNotEmpty$u20$as$u20$mini_core..FnOnce$LT$$LP$$RF$$RF$$u5b$u16$u5d$$C$$RP$$GT$$GT$9call_once17hd517c453d67c0915E +//! ; instance Instance { def: Item(WithOptConstParam { did: DefId(0:42 ~ example[4e51]::{impl#0}::call_once), const_param_did: None }), substs: [ReErased, ReErased] } +//! ; abi FnAbi { args: [ArgAbi { layout: TyAndLayout { ty: IsNotEmpty, layout: Layout { size: Size(0 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), pref: Align(8 bytes) }, abi: Aggregate { sized: true }, fields: Arbitrary { offsets: [], memory_index: [] }, largest_niche: None, variants: Single { index: 0 } } }, mode: Ignore }, ArgAbi { layout: TyAndLayout { ty: &&[u16], layout: Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: Scalar(Initialized { value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), fields: Primitive, largest_niche: Some(Niche { offset: Size(0 bytes), value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), variants: Single { index: 0 } } }, mode: Direct(ArgAttributes { regular: NonNull | NoUndef, arg_ext: None, pointee_size: Size(0 bytes), pointee_align: Some(Align(8 bytes)) }) }], ret: ArgAbi { layout: TyAndLayout { ty: (u8, u8), layout: Layout { size: Size(2 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), pref: Align(8 bytes) }, abi: ScalarPair(Initialized { value: Int(I8, false), valid_range: 0..=255 }, Initialized { value: Int(I8, false), valid_range: 0..=255 }), fields: Arbitrary { offsets: [Size(0 bytes), Size(1 bytes)], memory_index: [0, 1] }, largest_niche: None, variants: Single { index: 0 } } }, mode: Pair(ArgAttributes { regular: NoUndef, arg_ext: None, pointee_size: Size(0 bytes), pointee_align: None }, ArgAttributes { regular: NoUndef, arg_ext: None, pointee_size: Size(0 bytes), pointee_align: None }) }, c_variadic: false, fixed_count: 1, conv: Rust, can_unwind: false } //! -//! ; ssa {_2: NOT_SSA, _4: NOT_SSA, _0: NOT_SSA, _3: (empty), _1: NOT_SSA} -//! ; msg loc.idx param pass mode ssa flags ty -//! ; ret _0 = v0 ByRef NOT_SSA (u8, u8) -//! ; arg _1 = v1 ByRef NOT_SSA IsNotEmpty -//! ; arg _2.0 = v2 ByVal(types::I64) NOT_SSA &&[u16] +//! ; kind loc.idx param pass mode ty +//! ; ssa _0 (u8, u8) 2b 1, 8 var=(0, 1) +//! ; ret _0 - Pair(ArgAttributes { regular: NoUndef, arg_ext: None, pointee_size: Size(0 bytes), pointee_align: None }, ArgAttributes { regular: NoUndef, arg_ext: None, pointee_size: Size(0 bytes), pointee_align: None }) (u8, u8) +//! ; arg _1 - Ignore IsNotEmpty +//! ; arg _2.0 = v0 Direct(ArgAttributes { regular: NonNull | NoUndef, arg_ext: None, pointee_size: Size(0 bytes), pointee_align: Some(Align(8 bytes)) }) &&[u16] //! -//! ss0 = explicit_slot 0 ; _1: IsNotEmpty size=0 align=1,8 -//! ss1 = explicit_slot 8 ; _2: (&&[u16],) size=8 align=8,8 -//! ss2 = explicit_slot 8 ; _4: (&&[u16],) size=8 align=8,8 -//! sig0 = (i64, i64, i64) system_v -//! sig1 = (i64, i64, i64) system_v -//! fn0 = colocated u0:6 sig1 ; Instance { def: Item(DefId(0/0:31 ~ example[8787]::{{impl}}[1]::call_mut[0])), substs: [ReErased, ReErased] } +//! ; kind local ty size align (abi,pref) +//! ; zst _1 IsNotEmpty 0b 1, 8 align=8,offset= +//! ; stack _2 (&&[u16],) 8b 8, 8 storage=ss0 +//! ; ssa _3 &mut IsNotEmpty 8b 8, 8 var=2 //! -//! block0(v0: i64, v1: i64, v2: i64): -//! v3 = stack_addr.i64 ss0 -//! v4 = stack_addr.i64 ss1 -//! store v2, v4 -//! v5 = stack_addr.i64 ss2 +//! ss0 = explicit_slot 16 +//! sig0 = (i64, i64) -> i8, i8 system_v +//! fn0 = colocated u0:23 sig0 ; Instance { def: Item(WithOptConstParam { did: DefId(0:46 ~ example[4e51]::{impl#1}::call_mut), const_param_did: None }), substs: [ReErased, ReErased] } +//! +//! block0(v0: i64): +//! nop +//! ; write_cvalue: Addr(Pointer { base: Stack(ss0), offset: Offset32(0) }, None): &&[u16] <- ByVal(v0): &&[u16] +//! stack_store v0, ss0 //! jump block1 //! //! block1: //! nop //! ; _3 = &mut _1 -//! ; _4 = _2 -//! v6 = load.i64 v4 -//! store v6, v5 +//! v1 = iconst.i64 8 +//! ; write_cvalue: Var(_3, var2): &mut IsNotEmpty <- ByVal(v1): &mut IsNotEmpty //! ; -//! ; _0 = const mini_core::FnMut::call_mut(move _3, move _4) -//! v7 = load.i64 v5 -//! call fn0(v0, v3, v7) +//! ; _0 = >::call_mut(move _3, _2) +//! v2 = stack_load.i64 ss0 +//! v3, v4 = call fn0(v1, v2) ; v1 = 8 +//! v5 -> v3 +//! v6 -> v4 +//! ; write_cvalue: VarPair(_0, var0, var1): (u8, u8) <- ByValPair(v3, v4): (u8, u8) //! jump block2 //! //! block2: //! nop //! ; //! ; return -//! return +//! return v5, v6 //! } //! ``` diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 1b69862ce2c..c964d1ac5e0 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -2,8 +2,8 @@ use crate::prelude::*; +use cranelift_codegen::entity::EntityRef; use cranelift_codegen::ir::immediates::Offset32; -use cranelift_codegen::ir::{InstructionData, Opcode}; fn codegen_field<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, @@ -214,17 +214,7 @@ impl<'tcx> CValue<'tcx> { ) -> CValue<'tcx> { let layout = self.1; match self.0 { - CValueInner::ByVal(val) => match layout.abi { - Abi::Vector { element: _, count } => { - let count = u8::try_from(count).expect("SIMD type with more than 255 lanes???"); - let field = u8::try_from(field.index()).unwrap(); - assert!(field < count); - let lane = fx.bcx.ins().extractlane(val, field); - let field_layout = layout.field(&*fx, usize::from(field)); - CValue::by_val(lane, field_layout) - } - _ => unreachable!("value_field for ByVal with abi {:?}", layout.abi), - }, + CValueInner::ByVal(_) => unreachable!(), CValueInner::ByValPair(val1, val2) => match layout.abi { Abi::ScalarPair(_, _) => { let val = match field.as_u32() { @@ -258,16 +248,7 @@ impl<'tcx> CValue<'tcx> { let lane_layout = fx.layout_of(lane_ty); assert!(lane_idx < lane_count); match self.0 { - CValueInner::ByVal(val) => match layout.abi { - Abi::Vector { element: _, count: _ } => { - assert!(lane_count <= u8::MAX.into(), "SIMD type with more than 255 lanes???"); - let lane_idx = u8::try_from(lane_idx).unwrap(); - let lane = fx.bcx.ins().extractlane(val, lane_idx); - CValue::by_val(lane, lane_layout) - } - _ => unreachable!("value_lane for ByVal with abi {:?}", layout.abi), - }, - CValueInner::ByValPair(_, _) => unreachable!(), + CValueInner::ByVal(_) | CValueInner::ByValPair(_, _) => unreachable!(), CValueInner::ByRef(ptr, None) => { let field_offset = lane_layout.size * lane_idx; let field_ptr = ptr.offset_i64(fx, i64::try_from(field_offset.bytes()).unwrap()); @@ -277,14 +258,6 @@ impl<'tcx> CValue<'tcx> { } } - pub(crate) fn unsize_value(self, fx: &mut FunctionCx<'_, '_, 'tcx>, dest: CPlace<'tcx>) { - crate::unsize::coerce_unsized_into(fx, self, dest); - } - - pub(crate) fn coerce_dyn_star(self, fx: &mut FunctionCx<'_, '_, 'tcx>, dest: CPlace<'tcx>) { - crate::unsize::coerce_dyn_star(fx, self, dest); - } - /// If `ty` is signed, `const_val` must already be sign extended. pub(crate) fn const_val( fx: &mut FunctionCx<'_, '_, 'tcx>, @@ -345,10 +318,9 @@ pub(crate) struct CPlace<'tcx> { } #[derive(Debug, Copy, Clone)] -pub(crate) enum CPlaceInner { +enum CPlaceInner { Var(Local, Variable), VarPair(Local, Variable, Variable), - VarLane(Local, Variable, u8), Addr(Pointer, Option), } @@ -357,10 +329,6 @@ impl<'tcx> CPlace<'tcx> { self.layout } - pub(crate) fn inner(&self) -> &CPlaceInner { - &self.inner - } - pub(crate) fn new_stack_slot( fx: &mut FunctionCx<'_, '_, 'tcx>, layout: TyAndLayout<'tcx>, @@ -442,12 +410,6 @@ impl<'tcx> CPlace<'tcx> { //fx.bcx.set_val_label(val2, cranelift_codegen::ir::ValueLabel::new(var2.index())); CValue::by_val_pair(val1, val2, layout) } - CPlaceInner::VarLane(_local, var, lane) => { - let val = fx.bcx.use_var(var); - //fx.bcx.set_val_label(val, cranelift_codegen::ir::ValueLabel::new(var.index())); - let val = fx.bcx.ins().extractlane(val, lane); - CValue::by_val(val, layout) - } CPlaceInner::Addr(ptr, extra) => { if let Some(extra) = extra { CValue::by_ref_unsized(ptr, extra, layout) @@ -458,21 +420,56 @@ impl<'tcx> CPlace<'tcx> { } } - #[track_caller] - pub(crate) fn to_ptr(self) -> Pointer { - match self.to_ptr_maybe_unsized() { - (ptr, None) => ptr, - (_, Some(_)) => bug!("Expected sized cplace, found {:?}", self), + pub(crate) fn debug_comment(self) -> (&'static str, String) { + match self.inner { + CPlaceInner::Var(_local, var) => ("ssa", format!("var={}", var.index())), + CPlaceInner::VarPair(_local, var1, var2) => { + ("ssa", format!("var=({}, {})", var1.index(), var2.index())) + } + CPlaceInner::Addr(ptr, meta) => { + let meta = + if let Some(meta) = meta { format!(",meta={}", meta) } else { String::new() }; + match ptr.debug_base_and_offset() { + (crate::pointer::PointerBase::Addr(addr), offset) => { + ("reuse", format!("storage={}{}{}", addr, offset, meta)) + } + (crate::pointer::PointerBase::Stack(stack_slot), offset) => { + ("stack", format!("storage={}{}{}", stack_slot, offset, meta)) + } + (crate::pointer::PointerBase::Dangling(align), offset) => { + ("zst", format!("align={},offset={}", align.bytes(), offset)) + } + } + } } } #[track_caller] - pub(crate) fn to_ptr_maybe_unsized(self) -> (Pointer, Option) { + pub(crate) fn to_ptr(self) -> Pointer { match self.inner { - CPlaceInner::Addr(ptr, extra) => (ptr, extra), - CPlaceInner::Var(_, _) - | CPlaceInner::VarPair(_, _, _) - | CPlaceInner::VarLane(_, _, _) => bug!("Expected CPlace::Addr, found {:?}", self), + CPlaceInner::Addr(ptr, None) => ptr, + CPlaceInner::Addr(_, Some(_)) => bug!("Expected sized cplace, found {:?}", self), + CPlaceInner::Var(_, _) | CPlaceInner::VarPair(_, _, _) => { + bug!("Expected CPlace::Addr, found {:?}", self) + } + } + } + + #[track_caller] + pub(crate) fn to_ptr_unsized(self) -> (Pointer, Value) { + match self.inner { + CPlaceInner::Addr(ptr, Some(extra)) => (ptr, extra), + CPlaceInner::Addr(_, None) | CPlaceInner::Var(_, _) | CPlaceInner::VarPair(_, _, _) => { + bug!("Expected unsized cplace, found {:?}", self) + } + } + } + + pub(crate) fn try_to_ptr(self) -> Option { + match self.inner { + CPlaceInner::Var(_, _) | CPlaceInner::VarPair(_, _, _) => None, + CPlaceInner::Addr(ptr, None) => Some(ptr), + CPlaceInner::Addr(_, Some(_)) => bug!("Expected sized cplace, found {:?}", self), } } @@ -496,7 +493,7 @@ impl<'tcx> CPlace<'tcx> { from: CValue<'tcx>, method: &'static str, ) { - fn transmute_value<'tcx>( + fn transmute_scalar<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, var: Variable, data: Value, @@ -520,7 +517,7 @@ impl<'tcx> CPlace<'tcx> { | (types::F64, types::I64) => codegen_bitcast(fx, dst_ty, data), _ if src_ty.is_vector() && dst_ty.is_vector() => codegen_bitcast(fx, dst_ty, data), _ if src_ty.is_vector() || dst_ty.is_vector() => { - // FIXME do something more efficient for transmutes between vectors and integers. + // FIXME(bytecodealliance/wasmtime#6104) do something more efficient for transmutes between vectors and integers. let stack_slot = fx.bcx.create_sized_stack_slot(StackSlotData { kind: StackSlotKind::ExplicitSlot, // FIXME Don't force the size to a multiple of 16 bytes once Cranelift gets a way to @@ -554,7 +551,7 @@ impl<'tcx> CPlace<'tcx> { format!( "{}: {:?}: {:?} <- {:?}: {:?}", method, - self.inner(), + self.inner, self.layout().ty, from.0, from.layout().ty @@ -563,32 +560,11 @@ impl<'tcx> CPlace<'tcx> { } let dst_layout = self.layout(); - let to_ptr = match self.inner { + match self.inner { CPlaceInner::Var(_local, var) => { - if let ty::Array(element, len) = dst_layout.ty.kind() { - // Can only happen for vector types - let len = u32::try_from(len.eval_target_usize(fx.tcx, ParamEnv::reveal_all())) - .unwrap(); - let vector_ty = fx.clif_type(*element).unwrap().by(len).unwrap(); - - let data = match from.0 { - CValueInner::ByRef(ptr, None) => { - let mut flags = MemFlags::new(); - flags.set_notrap(); - ptr.load(fx, vector_ty, flags) - } - CValueInner::ByVal(_) - | CValueInner::ByValPair(_, _) - | CValueInner::ByRef(_, Some(_)) => bug!("array should be ByRef"), - }; - - fx.bcx.def_var(var, data); - return; - } let data = CValue(from.0, dst_layout).load_scalar(fx); let dst_ty = fx.clif_type(self.layout().ty).unwrap(); - transmute_value(fx, var, data, dst_ty); - return; + transmute_scalar(fx, var, data, dst_ty); } CPlaceInner::VarPair(_local, var1, var2) => { let (data1, data2) = if from.layout().ty == dst_layout.ty { @@ -599,80 +575,61 @@ impl<'tcx> CPlace<'tcx> { CValue(CValueInner::ByRef(ptr, None), dst_layout).load_scalar_pair(fx) }; let (dst_ty1, dst_ty2) = fx.clif_pair_type(self.layout().ty).unwrap(); - transmute_value(fx, var1, data1, dst_ty1); - transmute_value(fx, var2, data2, dst_ty2); - return; + transmute_scalar(fx, var1, data1, dst_ty1); + transmute_scalar(fx, var2, data2, dst_ty2); } - CPlaceInner::VarLane(_local, var, lane) => { - let data = from.load_scalar(fx); - - // First get the old vector - let vector = fx.bcx.use_var(var); - //fx.bcx.set_val_label(vector, cranelift_codegen::ir::ValueLabel::new(var.index())); - - // Next insert the written lane into the vector - let vector = fx.bcx.ins().insertlane(vector, data, lane); - - // Finally write the new vector - //fx.bcx.set_val_label(vector, cranelift_codegen::ir::ValueLabel::new(var.index())); - fx.bcx.def_var(var, vector); - - return; - } - CPlaceInner::Addr(ptr, None) => { + CPlaceInner::Addr(_, Some(_)) => bug!("Can't write value to unsized place {:?}", self), + CPlaceInner::Addr(to_ptr, None) => { if dst_layout.size == Size::ZERO || dst_layout.abi == Abi::Uninhabited { return; } - ptr - } - CPlaceInner::Addr(_, Some(_)) => bug!("Can't write value to unsized place {:?}", self), - }; - let mut flags = MemFlags::new(); - flags.set_notrap(); - match from.layout().abi { - // FIXME make Abi::Vector work too - Abi::Scalar(_) => { - let val = from.load_scalar(fx); - to_ptr.store(fx, val, flags); - return; - } - Abi::ScalarPair(a_scalar, b_scalar) => { - let (value, extra) = from.load_scalar_pair(fx); - let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar); - to_ptr.store(fx, value, flags); - to_ptr.offset(fx, b_offset).store(fx, extra, flags); - return; - } - _ => {} - } + let mut flags = MemFlags::new(); + flags.set_notrap(); + match from.layout().abi { + Abi::Scalar(_) => { + let val = from.load_scalar(fx); + to_ptr.store(fx, val, flags); + return; + } + Abi::ScalarPair(a_scalar, b_scalar) => { + let (value, extra) = from.load_scalar_pair(fx); + let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar); + to_ptr.store(fx, value, flags); + to_ptr.offset(fx, b_offset).store(fx, extra, flags); + return; + } + _ => {} + } - match from.0 { - CValueInner::ByVal(val) => { - to_ptr.store(fx, val, flags); + match from.0 { + CValueInner::ByVal(val) => { + to_ptr.store(fx, val, flags); + } + CValueInner::ByValPair(_, _) => { + bug!("Non ScalarPair abi {:?} for ByValPair CValue", dst_layout.abi); + } + CValueInner::ByRef(from_ptr, None) => { + let from_addr = from_ptr.get_addr(fx); + let to_addr = to_ptr.get_addr(fx); + let src_layout = from.1; + let size = dst_layout.size.bytes(); + let src_align = src_layout.align.abi.bytes() as u8; + let dst_align = dst_layout.align.abi.bytes() as u8; + fx.bcx.emit_small_memory_copy( + fx.target_config, + to_addr, + from_addr, + size, + dst_align, + src_align, + true, + flags, + ); + } + CValueInner::ByRef(_, Some(_)) => todo!(), + } } - CValueInner::ByValPair(_, _) => { - bug!("Non ScalarPair abi {:?} for ByValPair CValue", dst_layout.abi); - } - CValueInner::ByRef(from_ptr, None) => { - let from_addr = from_ptr.get_addr(fx); - let to_addr = to_ptr.get_addr(fx); - let src_layout = from.1; - let size = dst_layout.size.bytes(); - let src_align = src_layout.align.abi.bytes() as u8; - let dst_align = dst_layout.align.abi.bytes() as u8; - fx.bcx.emit_small_memory_copy( - fx.target_config, - to_addr, - from_addr, - size, - dst_align, - src_align, - true, - flags, - ); - } - CValueInner::ByRef(_, Some(_)) => todo!(), } } @@ -692,40 +649,6 @@ impl<'tcx> CPlace<'tcx> { let layout = self.layout(); match self.inner { - CPlaceInner::Var(local, var) => match layout.ty.kind() { - ty::Array(_, _) => { - // Can only happen for vector types - return CPlace { - inner: CPlaceInner::VarLane(local, var, field.as_u32().try_into().unwrap()), - layout: layout.field(fx, field.as_u32().try_into().unwrap()), - }; - } - ty::Adt(adt_def, substs) if layout.ty.is_simd() => { - let f0 = &adt_def.non_enum_variant().fields[FieldIdx::from_u32(0)]; - let f0_ty = f0.ty(fx.tcx, substs); - - match f0_ty.kind() { - ty::Array(_, _) => { - assert_eq!(field.as_u32(), 0); - return CPlace { - inner: CPlaceInner::Var(local, var), - layout: layout.field(fx, field.as_u32().try_into().unwrap()), - }; - } - _ => { - return CPlace { - inner: CPlaceInner::VarLane( - local, - var, - field.as_u32().try_into().unwrap(), - ), - layout: layout.field(fx, field.as_u32().try_into().unwrap()), - }; - } - } - } - _ => {} - }, CPlaceInner::VarPair(local, var1, var2) => { let layout = layout.field(&*fx, field.index()); @@ -738,7 +661,12 @@ impl<'tcx> CPlace<'tcx> { _ => {} } - let (base, extra) = self.to_ptr_maybe_unsized(); + let (base, extra) = match self.inner { + CPlaceInner::Addr(ptr, extra) => (ptr, extra), + CPlaceInner::Var(_, _) | CPlaceInner::VarPair(_, _, _) => { + bug!("Expected CPlace::Addr, found {:?}", self) + } + }; let (field_ptr, field_layout) = codegen_field(fx, base, extra, layout, field); if field_layout.is_unsized() { @@ -767,15 +695,8 @@ impl<'tcx> CPlace<'tcx> { assert!(lane_idx < lane_count); match self.inner { - CPlaceInner::Var(local, var) => { - assert!(matches!(layout.abi, Abi::Vector { .. })); - CPlace { - inner: CPlaceInner::VarLane(local, var, lane_idx.try_into().unwrap()), - layout: lane_layout, - } - } + CPlaceInner::Var(_, _) => unreachable!(), CPlaceInner::VarPair(_, _, _) => unreachable!(), - CPlaceInner::VarLane(_, _, _) => unreachable!(), CPlaceInner::Addr(ptr, None) => { let field_offset = lane_layout.size * lane_idx; let field_ptr = ptr.offset_i64(fx, i64::try_from(field_offset.bytes()).unwrap()); @@ -794,34 +715,13 @@ impl<'tcx> CPlace<'tcx> { ty::Array(elem_ty, _) => { let elem_layout = fx.layout_of(*elem_ty); match self.inner { - CPlaceInner::Var(local, var) => { - // This is a hack to handle `vector_val.0[1]`. It doesn't allow dynamic - // indexing. - let lane_idx = match fx.bcx.func.dfg.insts - [fx.bcx.func.dfg.value_def(index).unwrap_inst()] - { - InstructionData::UnaryImm { opcode: Opcode::Iconst, imm } => imm, - _ => bug!( - "Dynamic indexing into a vector type is not supported: {self:?}[{index}]" - ), - }; - return CPlace { - inner: CPlaceInner::VarLane( - local, - var, - lane_idx.bits().try_into().unwrap(), - ), - layout: elem_layout, - }; - } CPlaceInner::Addr(addr, None) => (elem_layout, addr), - CPlaceInner::Addr(_, Some(_)) - | CPlaceInner::VarPair(_, _, _) - | CPlaceInner::VarLane(_, _, _) => bug!("Can't index into {self:?}"), + CPlaceInner::Var(_, _) + | CPlaceInner::Addr(_, Some(_)) + | CPlaceInner::VarPair(_, _, _) => bug!("Can't index into {self:?}"), } - // FIXME use VarLane in case of Var with simd type } - ty::Slice(elem_ty) => (fx.layout_of(*elem_ty), self.to_ptr_maybe_unsized().0), + ty::Slice(elem_ty) => (fx.layout_of(*elem_ty), self.to_ptr_unsized().0), _ => bug!("place_index({:?})", self.layout().ty), }; @@ -846,12 +746,8 @@ impl<'tcx> CPlace<'tcx> { layout: TyAndLayout<'tcx>, ) -> CValue<'tcx> { if has_ptr_meta(fx.tcx, self.layout().ty) { - let (ptr, extra) = self.to_ptr_maybe_unsized(); - CValue::by_val_pair( - ptr.get_addr(fx), - extra.expect("unsized type without metadata"), - layout, - ) + let (ptr, extra) = self.to_ptr_unsized(); + CValue::by_val_pair(ptr.get_addr(fx), extra, layout) } else { CValue::by_val(self.to_ptr().get_addr(fx), layout) } diff --git a/y.rs b/y.rs index fd825d02e35..a68a10500f5 100755 --- a/y.rs +++ b/y.rs @@ -3,10 +3,14 @@ # This block is ignored by rustc set -e echo "[BUILD] y.rs" 1>&2 -rustc $0 -o ${0/.rs/.bin} -Cdebuginfo=1 --edition 2021 -Cpanic=abort +rustc $0 -o ${0/.rs/.bin} -Cdebuginfo=1 --edition 2021 exec ${0/.rs/.bin} $@ */ +#![warn(rust_2018_idioms)] +#![warn(unused_lifetimes)] +#![warn(unreachable_pub)] + //! The build system for cg_clif //! //! # Manual compilation From 215dd7aa0d70cf7396100715326a37c81b06f056 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 29 Apr 2023 13:31:06 +0000 Subject: [PATCH 02/89] Add some extra instructions for using the precompiled builds --- Readme.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Readme.md b/Readme.md index c5222982aa7..34801dd7e0c 100644 --- a/Readme.md +++ b/Readme.md @@ -22,7 +22,12 @@ $ ./test.sh For more docs on how to build and test see [build_system/usage.txt](build_system/usage.txt) or the help message of `./y.rs`. +## Precompiled builds + Alternatively you can download a pre built version from the [releases] page. +Extract the `dist` directory in the archive anywhere you want. +If you want to use `cargo clif build` instead of having to specify the full path to the `cargo-clif` executable, you can add the `bin` subdirectory of the extracted `dist` directory to your `PATH`. +(tutorial [for Windows](https://stackoverflow.com/a/44272417), and [for Linux/MacOS](https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path/26059#26059)). [releases]: https://github.com/bjorn3/rustc_codegen_cranelift/releases/tag/dev From 249a6f8fe1d3bee8e5bc63e5a79a68fca62709c3 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Mon, 1 May 2023 18:30:54 -0400 Subject: [PATCH 03/89] Box AssertKind --- src/base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index a259a4f30b2..527f455edbe 100644 --- a/src/base.rs +++ b/src/base.rs @@ -335,7 +335,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { fx.bcx.switch_to_block(failure); fx.bcx.ins().nop(); - match msg { + match &**msg { AssertKind::BoundsCheck { ref len, ref index } => { let len = codegen_operand(fx, len).load_scalar(fx); let index = codegen_operand(fx, index).load_scalar(fx); From a4c49374cb363e48751272166023de0868df02af Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 20 Apr 2023 13:26:58 +1000 Subject: [PATCH 04/89] Restrict `From` for `{D,Subd}iagnosticMessage`. Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile. --- src/abi/mod.rs | 8 ++++---- src/base.rs | 4 ++-- src/common.rs | 4 ++-- src/concurrency_limiter.rs | 2 +- src/constant.rs | 8 ++++---- src/driver/aot.rs | 4 ++-- src/intrinsics/llvm.rs | 2 +- src/intrinsics/llvm_aarch64.rs | 2 +- src/intrinsics/llvm_x86.rs | 7 +++---- src/intrinsics/mod.rs | 4 ++-- src/intrinsics/simd.rs | 14 +++++++------- src/lib.rs | 10 +++++----- src/main_shim.rs | 4 ++-- src/value_and_place.rs | 2 +- 14 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index e533afcfaa9..73a3e3353f3 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -88,10 +88,10 @@ pub(crate) fn import_function<'tcx>( let sig = get_function_sig(tcx, module.target_config().default_call_conv, inst); match module.declare_function(name, Linkage::Import, &sig) { Ok(func_id) => func_id, - Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(&format!( + Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(format!( "attempt to declare `{name}` as function, but it was already declared as static" )), - Err(ModuleError::IncompatibleSignature(_, prev_sig, new_sig)) => tcx.sess.fatal(&format!( + Err(ModuleError::IncompatibleSignature(_, prev_sig, new_sig)) => tcx.sess.fatal(format!( "attempt to declare `{name}` with signature {new_sig:?}, \ but it was already declared with signature {prev_sig:?}" )), @@ -548,7 +548,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( if !matches!(fn_sig.abi(), Abi::C { .. }) { fx.tcx.sess.span_fatal( source_info.span, - &format!("Variadic call for non-C abi {:?}", fn_sig.abi()), + format!("Variadic call for non-C abi {:?}", fn_sig.abi()), ); } let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap(); @@ -560,7 +560,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( // FIXME set %al to upperbound on float args once floats are supported fx.tcx.sess.span_fatal( source_info.span, - &format!("Non int ty {:?} for variadic call", ty), + format!("Non int ty {:?} for variadic call", ty), ); } AbiParam::new(ty) diff --git a/src/base.rs b/src/base.rs index 527f455edbe..e9dbea1be67 100644 --- a/src/base.rs +++ b/src/base.rs @@ -220,13 +220,13 @@ pub(crate) fn verify_func( match cranelift_codegen::verify_function(&func, &flags) { Ok(_) => {} Err(err) => { - tcx.sess.err(&format!("{:?}", err)); + tcx.sess.err(format!("{:?}", err)); let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error( &func, Some(Box::new(writer)), err, ); - tcx.sess.fatal(&format!("cranelift verify error:\n{}", pretty_error)); + tcx.sess.fatal(format!("cranelift verify error:\n{}", pretty_error)); } } }); diff --git a/src/common.rs b/src/common.rs index 30f4cf4473c..264b95e7abd 100644 --- a/src/common.rs +++ b/src/common.rs @@ -481,7 +481,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> { #[inline] fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! { if let layout::LayoutError::SizeOverflow(_) = err { - self.0.sess.span_fatal(span, &err.to_string()) + self.0.sess.span_fatal(span, err.to_string()) } else { span_bug!(span, "failed to get layout for `{}`: {}", ty, err) } @@ -499,7 +499,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> { fn_abi_request: FnAbiRequest<'tcx>, ) -> ! { if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err { - self.0.sess.span_fatal(span, &err.to_string()) + self.0.sess.span_fatal(span, err.to_string()) } else { match fn_abi_request { FnAbiRequest::OfFnPtr { sig, extra_args } => { diff --git a/src/concurrency_limiter.rs b/src/concurrency_limiter.rs index 54df04f8c2c..d2b928db7d4 100644 --- a/src/concurrency_limiter.rs +++ b/src/concurrency_limiter.rs @@ -65,7 +65,7 @@ impl ConcurrencyLimiter { // Make sure to drop the mutex guard first to prevent poisoning the mutex. drop(state); if let Some(err) = err { - handler.fatal(&err).raise(); + handler.fatal(err).raise(); } else { // The error was already emitted, but compilation continued. Raise a silent // fatal error. diff --git a/src/constant.rs b/src/constant.rs index bf5d29c16f6..77af561a587 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -308,7 +308,7 @@ fn data_id_for_static( attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL), ) { Ok(data_id) => data_id, - Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(&format!( + Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(format!( "attempt to declare `{symbol_name}` as static, but it was already declared as function" )), Err(err) => Err::<_, _>(err).unwrap(), @@ -356,7 +356,7 @@ fn data_id_for_static( attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL), ) { Ok(data_id) => data_id, - Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(&format!( + Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(format!( "attempt to declare `{symbol_name}` as static, but it was already declared as function" )), Err(err) => Err::<_, _>(err).unwrap(), @@ -404,7 +404,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant if let Some(names) = section_name.split_once(',') { names } else { - tcx.sess.fatal(&format!( + tcx.sess.fatal(format!( "#[link_section = \"{}\"] is not valid for macos target: must be segment and section separated by comma", section_name )); @@ -449,7 +449,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant GlobalAlloc::Static(def_id) => { if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) { - tcx.sess.fatal(&format!( + tcx.sess.fatal(format!( "Allocation {:?} contains reference to TLS value {:?}", alloc_id, def_id )); diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 0e6c6ad95aa..aad9a9647f8 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -69,7 +69,7 @@ impl OngoingCodegen { let module_codegen_result = match module_codegen_result { Ok(module_codegen_result) => module_codegen_result, - Err(err) => sess.fatal(&err), + Err(err) => sess.fatal(err), }; let ModuleCodegenResult { module_regular, module_global_asm, existing_work_product } = module_codegen_result; @@ -468,7 +468,7 @@ pub(crate) fn run_aot( let obj = create_compressed_metadata_file(tcx.sess, &metadata, &symbol_name); if let Err(err) = std::fs::write(&tmp_file, obj) { - tcx.sess.fatal(&format!("error writing metadata object file: {}", err)); + tcx.sess.fatal(format!("error writing metadata object file: {}", err)); } (metadata_cgu_name, tmp_file) diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index f722e52284f..f67fdb59270 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -42,7 +42,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( _ => { fx.tcx .sess - .warn(&format!("unsupported llvm intrinsic {}; replacing with trap", intrinsic)); + .warn(format!("unsupported llvm intrinsic {}; replacing with trap", intrinsic)); crate::trap::trap_unimplemented(fx, intrinsic); return; } diff --git a/src/intrinsics/llvm_aarch64.rs b/src/intrinsics/llvm_aarch64.rs index b431158d269..33b2f4702a7 100644 --- a/src/intrinsics/llvm_aarch64.rs +++ b/src/intrinsics/llvm_aarch64.rs @@ -207,7 +207,7 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>( } */ _ => { - fx.tcx.sess.warn(&format!( + fx.tcx.sess.warn(format!( "unsupported AArch64 llvm intrinsic {}; replacing with trap", intrinsic )); diff --git a/src/intrinsics/llvm_x86.rs b/src/intrinsics/llvm_x86.rs index 0f32d1a25ff..56d8f13cec5 100644 --- a/src/intrinsics/llvm_x86.rs +++ b/src/intrinsics/llvm_x86.rs @@ -138,10 +138,9 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>( llvm_add_sub(fx, BinOp::Sub, ret, b_in, a, b); } _ => { - fx.tcx.sess.warn(&format!( - "unsupported x86 llvm intrinsic {}; replacing with trap", - intrinsic - )); + fx.tcx + .sess + .warn(format!("unsupported x86 llvm intrinsic {}; replacing with trap", intrinsic)); crate::trap::trap_unimplemented(fx, intrinsic); return; } diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 539f8c103db..0a513b08b74 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -42,7 +42,7 @@ fn report_atomic_type_validation_error<'tcx>( ) { fx.tcx.sess.span_err( span, - &format!( + format!( "`{}` intrinsic: expected basic integer or raw pointer type, found `{:?}`", intrinsic, ty ), @@ -1202,7 +1202,7 @@ fn codegen_regular_intrinsic_call<'tcx>( _ => { fx.tcx .sess - .span_fatal(source_info.span, &format!("unsupported intrinsic {}", intrinsic)); + .span_fatal(source_info.span, format!("unsupported intrinsic {}", intrinsic)); } } diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 264b578c168..5a038bfca5d 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -13,7 +13,7 @@ fn report_simd_type_validation_error( span: Span, ty: Ty<'_>, ) { - fx.tcx.sess.span_err(span, &format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", intrinsic, ty)); + fx.tcx.sess.span_err(span, format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", intrinsic, ty)); // Prevent verifier error fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } @@ -150,7 +150,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( _ => { fx.tcx.sess.span_err( span, - &format!( + format!( "simd_shuffle index must be an array of `u32`, got `{}`", idx_ty, ), @@ -248,7 +248,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( if idx >= lane_count.into() { fx.tcx.sess.span_fatal( fx.mir.span, - &format!("[simd_insert] idx {} >= lane_count {}", idx, lane_count), + format!("[simd_insert] idx {} >= lane_count {}", idx, lane_count), ); } @@ -296,7 +296,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( if idx >= lane_count.into() { fx.tcx.sess.span_fatal( fx.mir.span, - &format!("[simd_extract] idx {} >= lane_count {}", idx, lane_count), + format!("[simd_extract] idx {} >= lane_count {}", idx, lane_count), ); } @@ -699,7 +699,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( _ => { fx.tcx.sess.span_fatal( span, - &format!( + format!( "invalid monomorphization of `simd_bitmask` intrinsic: \ vector argument `{}`'s element type `{}`, expected integer element \ type", @@ -739,7 +739,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( _ => { fx.tcx.sess.span_fatal( span, - &format!( + format!( "invalid monomorphization of `simd_bitmask` intrinsic: \ cannot return `{}`, expected `u{}` or `[u8; {}]`", ret.layout().ty, @@ -875,7 +875,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( } _ => { - fx.tcx.sess.span_err(span, &format!("Unknown SIMD intrinsic {}", intrinsic)); + fx.tcx.sess.span_err(span, format!("Unknown SIMD intrinsic {}", intrinsic)); // Prevent verifier error fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } diff --git a/src/lib.rs b/src/lib.rs index f0b399ae280..9966cc2ef3c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,7 +185,7 @@ impl CodegenBackend for CraneliftCodegenBackend { let mut config = self.config.borrow_mut(); if config.is_none() { let new_config = BackendConfig::from_opts(&sess.opts.cg.llvm_args) - .unwrap_or_else(|err| sess.fatal(&err)); + .unwrap_or_else(|err| sess.fatal(err)); *config = Some(new_config); } } @@ -245,7 +245,7 @@ impl CodegenBackend for CraneliftCodegenBackend { fn target_triple(sess: &Session) -> target_lexicon::Triple { match sess.target.llvm_target.parse() { Ok(triple) => triple, - Err(err) => sess.fatal(&format!("target not recognized: {}", err)), + Err(err) => sess.fatal(format!("target not recognized: {}", err)), } } @@ -307,7 +307,7 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc { let mut builder = cranelift_codegen::isa::lookup(target_triple.clone()).unwrap_or_else(|err| { - sess.fatal(&format!("can't compile for {}: {}", target_triple, err)); + sess.fatal(format!("can't compile for {}: {}", target_triple, err)); }); if let Err(_) = builder.enable(value) { sess.fatal("the specified target cpu isn't currently supported by Cranelift."); @@ -317,7 +317,7 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc { let mut builder = cranelift_codegen::isa::lookup(target_triple.clone()).unwrap_or_else(|err| { - sess.fatal(&format!("can't compile for {}: {}", target_triple, err)); + sess.fatal(format!("can't compile for {}: {}", target_triple, err)); }); if target_triple.architecture == target_lexicon::Architecture::X86_64 { // Don't use "haswell" as the default, as it implies `has_lzcnt`. @@ -330,7 +330,7 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc target_isa, - Err(err) => sess.fatal(&format!("failed to build TargetIsa: {}", err)), + Err(err) => sess.fatal(format!("failed to build TargetIsa: {}", err)), } } diff --git a/src/main_shim.rs b/src/main_shim.rs index 205411e8c27..20ba73f3852 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -75,7 +75,7 @@ pub(crate) fn maybe_create_entry_wrapper( Ok(func_id) => func_id, Err(err) => { tcx.sess - .fatal(&format!("entry symbol `{entry_name}` declared multiple times: {err}")); + .fatal(format!("entry symbol `{entry_name}` declared multiple times: {err}")); } }; @@ -171,7 +171,7 @@ pub(crate) fn maybe_create_entry_wrapper( } if let Err(err) = m.define_function(cmain_func_id, &mut ctx) { - tcx.sess.fatal(&format!("entry symbol `{entry_name}` defined multiple times: {err}")); + tcx.sess.fatal(format!("entry symbol `{entry_name}` defined multiple times: {err}")); } unwind_context.add_function(cmain_func_id, &ctx, m.isa()); diff --git a/src/value_and_place.rs b/src/value_and_place.rs index c964d1ac5e0..b1fda6ff213 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -344,7 +344,7 @@ impl<'tcx> CPlace<'tcx> { if layout.size.bytes() >= u64::from(u32::MAX - 16) { fx.tcx .sess - .fatal(&format!("values of type {} are too big to store on the stack", layout.ty)); + .fatal(format!("values of type {} are too big to store on the stack", layout.ty)); } let stack_slot = fx.bcx.create_sized_stack_slot(StackSlotData { From edd0e5df3b4f9d291f045e869f7e67e7ded8a94f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 4 May 2023 10:21:07 +0000 Subject: [PATCH 05/89] Rustup to rustc 1.71.0-nightly (473f916d8 2023-05-03) --- rust-toolchain | 2 +- src/driver/jit.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust-toolchain b/rust-toolchain index 59ad80c3207..f5c196a8e70 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-04-29" +channel = "nightly-2023-05-04" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 3118105a4e2..62a3e096912 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -325,7 +325,7 @@ fn dep_symbol_lookup_fn( Linkage::NotLinked | Linkage::IncludedFromDylib => {} Linkage::Static => { let name = crate_info.crate_name[&cnum]; - let mut err = sess.struct_err(&format!("Can't load static lib {}", name)); + let mut err = sess.struct_err(format!("Can't load static lib {}", name)); err.note("rustc_codegen_cranelift can only load dylibs in JIT mode."); err.emit(); } From 7905fa92ce86167625d5b87c402bc0cef9497124 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 4 May 2023 11:24:58 +0000 Subject: [PATCH 06/89] Fix rustc test suite --- scripts/rustc-clif.rs | 4 +++- scripts/rustdoc-clif.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/rustc-clif.rs b/scripts/rustc-clif.rs index ab496a4a684..7ef3488672d 100644 --- a/scripts/rustc-clif.rs +++ b/scripts/rustc-clif.rs @@ -22,7 +22,9 @@ fn main() { let mut codegen_backend_arg = OsString::from("-Zcodegen-backend="); codegen_backend_arg.push(cg_clif_dylib_path); args.push(codegen_backend_arg); - if !passed_args.contains(&OsString::from("--sysroot")) { + if !passed_args.iter().any(|arg| { + arg == "--sysroot" || arg.to_str().map(|s| s.starts_with("--sysroot=")) == Some(true) + }) { args.push(OsString::from("--sysroot")); args.push(OsString::from(sysroot.to_str().unwrap())); } diff --git a/scripts/rustdoc-clif.rs b/scripts/rustdoc-clif.rs index 545844446c5..72024e0d494 100644 --- a/scripts/rustdoc-clif.rs +++ b/scripts/rustdoc-clif.rs @@ -22,7 +22,9 @@ fn main() { let mut codegen_backend_arg = OsString::from("-Zcodegen-backend="); codegen_backend_arg.push(cg_clif_dylib_path); args.push(codegen_backend_arg); - if !passed_args.contains(&OsString::from("--sysroot")) { + if !passed_args.iter().any(|arg| { + arg == "--sysroot" || arg.to_str().map(|s| s.starts_with("--sysroot=")) == Some(true) + }) { args.push(OsString::from("--sysroot")); args.push(OsString::from(sysroot.to_str().unwrap())); } From 332b54a6d3db0d4936d98f0cf8b8ace32c20ffd8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 5 May 2023 12:45:06 +0000 Subject: [PATCH 07/89] Rustup to rustc 1.71.0-nightly (74c482104 2023-05-04) --- build_sysroot/Cargo.lock | 3 +-- build_sysroot/Cargo.toml | 1 + rust-toolchain | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 7ddf91ad01f..7755943bf3a 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -261,7 +261,6 @@ version = "0.1.5" dependencies = [ "cfg-if", "compiler_builtins", - "libc", "rustc-std-workspace-alloc", "rustc-std-workspace-core", ] @@ -273,6 +272,7 @@ dependencies = [ "alloc", "compiler_builtins", "core", + "proc_macro", "std", "test", ] @@ -285,7 +285,6 @@ dependencies = [ "getopts", "panic_abort", "panic_unwind", - "proc_macro", "std", ] diff --git a/build_sysroot/Cargo.toml b/build_sysroot/Cargo.toml index 8219e6b6ccf..ea9d1c8df1c 100644 --- a/build_sysroot/Cargo.toml +++ b/build_sysroot/Cargo.toml @@ -7,6 +7,7 @@ core = { path = "./sysroot_src/library/core" } alloc = { path = "./sysroot_src/library/alloc" } std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] } test = { path = "./sysroot_src/library/test" } +proc_macro = { path = "./sysroot_src/library/proc_macro" } compiler_builtins = { version = "0.1.87", default-features = false, features = ["no-asm"] } diff --git a/rust-toolchain b/rust-toolchain index f5c196a8e70..056268c61e6 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-05-04" +channel = "nightly-2023-05-05" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 4ef286c03827dced34d0b0a709490d82e160761f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 5 May 2023 12:45:31 +0000 Subject: [PATCH 08/89] Fix rustc test suite --- scripts/test_rustc_tests.sh | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 1329d3ea076..23792955462 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -10,12 +10,17 @@ pushd rust command -v rg >/dev/null 2>&1 || cargo install ripgrep -# FIXME add needs-asm-support to all tests in tests/ui/asm rm -r tests/ui/{unsized-locals/,lto/,linkage*} || true for test in $(rg --files-with-matches "lto|// needs-asm-support|// needs-unwind" tests/{codegen-units,ui,incremental}); do rm $test done +for test in tests/run-make/**/Makefile; do + if rg "# needs-asm-support|# needs-unwind" $test >/dev/null; then + rm -r $(dirname $test) + fi +done + for test in $(rg -i --files-with-matches "//(\[\w+\])?~[^\|]*\s*ERR|// error-pattern:|// build-fail|// run-fail|-Cllvm-args" tests/ui); do rm $test done @@ -28,24 +33,8 @@ rm tests/ui/parser/unclosed-delimiter-in-dep.rs # submodule contains //~ERROR # ================ # requires stack unwinding -# FIXME add needs-unwind to these tests -rm tests/incremental/change_crate_dep_kind.rs -rm tests/incremental/issue-80691-bad-eval-cache.rs # -Cpanic=abort causes abort instead of exit(101) -rm -r tests/run-make/c-unwind-abi-catch-lib-panic -rm -r tests/run-make/c-unwind-abi-catch-panic -rm -r tests/run-make/debug-assertions -rm -r tests/run-make/foreign-double-unwind -rm -r tests/run-make/foreign-exceptions -rm -r tests/run-make/foreign-rust-exceptions -rm -r tests/run-make/libtest-json -rm -r tests/run-make/static-unwinding - -# requires compiling with -Cpanic=unwind -rm -r tests/ui/macros/rfc-2011-nicer-assert-messages/ -rm -r tests/run-make/test-benches -rm tests/ui/test-attrs/test-type.rs -rm -r tests/run-make/const_fn_mir -rm -r tests/run-make/intrinsic-unreachable +# FIXME add needs-unwind to this test +rm -r tests/run-make/libtest-junit # vendor intrinsics rm tests/ui/sse2.rs # cpuid not supported, so sse2 not detected From dfb11195da245a1f2fe04a4c976e49312a681edd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 5 May 2023 18:55:34 +0000 Subject: [PATCH 09/89] Replace once_cell with the newly stabilized std::sync::OnceLock --- Cargo.lock | 1 - Cargo.toml | 1 - src/driver/jit.rs | 7 ++----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 07a8e431a0e..d25bc52caa0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -327,7 +327,6 @@ dependencies = [ "indexmap", "libloading", "object", - "once_cell", "smallvec", "target-lexicon", ] diff --git a/Cargo.toml b/Cargo.toml index a2890f6ddf9..85b9c0a8464 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,6 @@ object = { version = "0.30.3", default-features = false, features = ["std", "rea indexmap = "1.9.3" libloading = { version = "0.7.3", optional = true } -once_cell = "1.10.0" smallvec = "1.8.1" [patch.crates-io] diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 62a3e096912..41e24acefbe 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -4,7 +4,7 @@ use std::cell::RefCell; use std::ffi::CString; use std::os::raw::{c_char, c_int}; -use std::sync::{mpsc, Mutex}; +use std::sync::{mpsc, Mutex, OnceLock}; use rustc_codegen_ssa::CrateInfo; use rustc_middle::mir::mono::MonoItem; @@ -13,9 +13,6 @@ use rustc_span::Symbol; use cranelift_jit::{JITBuilder, JITModule}; -// FIXME use std::sync::OnceLock once it stabilizes -use once_cell::sync::OnceCell; - use crate::{prelude::*, BackendConfig}; use crate::{CodegenCx, CodegenMode}; @@ -29,7 +26,7 @@ thread_local! { } /// The Sender owned by the rustc thread -static GLOBAL_MESSAGE_SENDER: OnceCell>> = OnceCell::new(); +static GLOBAL_MESSAGE_SENDER: OnceLock>> = OnceLock::new(); /// A message that is sent from the jitted runtime to the rustc thread. /// Senders are responsible for upholding `Send` semantics. From db3faa78d0cdba3d90f559ce4d7a4e56a341950b Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Fri, 14 Apr 2023 09:59:03 -0600 Subject: [PATCH 10/89] use EarlyBinder in tcx.(try_)subst_mir_and_normalize_erasing_regions --- src/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.rs b/src/common.rs index 264b95e7abd..ccb3a0c4f27 100644 --- a/src/common.rs +++ b/src/common.rs @@ -361,7 +361,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { self.instance.subst_mir_and_normalize_erasing_regions( self.tcx, ty::ParamEnv::reveal_all(), - value, + ty::EarlyBinder(value), ) } From 002aa8ed9026746414cc048f0ad8aefb56f4905a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 3 Jul 2021 16:46:41 +0200 Subject: [PATCH 11/89] Don't use an allocator shim for `#[global_allocator]` This makes it possible to use liballoc/libstd in combination with `--emit obj` if you use `#[global_allocator]`. Making it work for the default libstd allocator would require weak functions, which are not well supported on all systems. --- src/allocator.rs | 73 +++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index 2c246ceb37d..ef69d3f7800 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -3,10 +3,11 @@ use crate::prelude::*; -use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS}; +use rustc_ast::expand::allocator::{ + alloc_error_handler_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS, +}; use rustc_codegen_ssa::base::allocator_kind_for_codegen; use rustc_session::config::OomStrategy; -use rustc_span::symbol::sym; /// Returns whether an allocator shim was created pub(crate) fn codegen( @@ -34,41 +35,43 @@ fn codegen_inner( ) { let usize_ty = module.target_config().pointer_type(); - for method in ALLOCATOR_METHODS { - let mut arg_tys = Vec::with_capacity(method.inputs.len()); - for ty in method.inputs.iter() { - match *ty { - AllocatorTy::Layout => { - arg_tys.push(usize_ty); // size - arg_tys.push(usize_ty); // align + if kind == AllocatorKind::Default { + for method in ALLOCATOR_METHODS { + let mut arg_tys = Vec::with_capacity(method.inputs.len()); + for ty in method.inputs.iter() { + match *ty { + AllocatorTy::Layout => { + arg_tys.push(usize_ty); // size + arg_tys.push(usize_ty); // align + } + AllocatorTy::Ptr => arg_tys.push(usize_ty), + AllocatorTy::Usize => arg_tys.push(usize_ty), + + AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"), } - AllocatorTy::Ptr => arg_tys.push(usize_ty), - AllocatorTy::Usize => arg_tys.push(usize_ty), - - AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"), } + let output = match method.output { + AllocatorTy::ResultPtr => Some(usize_ty), + AllocatorTy::Unit => None, + + AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => { + panic!("invalid allocator output") + } + }; + + let sig = Signature { + call_conv: module.target_config().default_call_conv, + params: arg_tys.iter().cloned().map(AbiParam::new).collect(), + returns: output.into_iter().map(AbiParam::new).collect(), + }; + crate::common::create_wrapper_function( + module, + unwind_context, + sig, + &format!("__rust_{}", method.name), + &AllocatorKind::Default.fn_name(method.name), + ); } - let output = match method.output { - AllocatorTy::ResultPtr => Some(usize_ty), - AllocatorTy::Unit => None, - - AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => { - panic!("invalid allocator output") - } - }; - - let sig = Signature { - call_conv: module.target_config().default_call_conv, - params: arg_tys.iter().cloned().map(AbiParam::new).collect(), - returns: output.into_iter().map(AbiParam::new).collect(), - }; - crate::common::create_wrapper_function( - module, - unwind_context, - sig, - &format!("__rust_{}", method.name), - &kind.fn_name(method.name), - ); } let sig = Signature { @@ -81,7 +84,7 @@ fn codegen_inner( unwind_context, sig, "__rust_alloc_error_handler", - &alloc_error_handler_kind.fn_name(sym::oom), + &alloc_error_handler_name(alloc_error_handler_kind), ); let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap(); From 59305092727515852a394ab2d8c66fe107dc3a21 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 3 Jul 2021 17:50:53 +0200 Subject: [PATCH 12/89] Split AllocatorKind::fn_name in global_fn_name and default_fn_name --- src/allocator.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index ef69d3f7800..3b74050250b 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -4,7 +4,7 @@ use crate::prelude::*; use rustc_ast::expand::allocator::{ - alloc_error_handler_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS, + alloc_error_handler_name, default_fn_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS, }; use rustc_codegen_ssa::base::allocator_kind_for_codegen; use rustc_session::config::OomStrategy; @@ -69,7 +69,7 @@ fn codegen_inner( unwind_context, sig, &format!("__rust_{}", method.name), - &AllocatorKind::Default.fn_name(method.name), + &default_fn_name(method.name), ); } } From a1d0a902c3aa792bf3eb34d90fd9289b55d29965 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 6 Jul 2021 18:56:01 +0200 Subject: [PATCH 13/89] Use global_fn_name instead of format! --- src/allocator.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index 3b74050250b..c27971897a0 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -4,7 +4,8 @@ use crate::prelude::*; use rustc_ast::expand::allocator::{ - alloc_error_handler_name, default_fn_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS, + alloc_error_handler_name, default_fn_name, global_fn_name, AllocatorKind, AllocatorTy, + ALLOCATOR_METHODS, }; use rustc_codegen_ssa::base::allocator_kind_for_codegen; use rustc_session::config::OomStrategy; @@ -68,7 +69,7 @@ fn codegen_inner( module, unwind_context, sig, - &format!("__rust_{}", method.name), + &global_fn_name(method.name), &default_fn_name(method.name), ); } From 2253e866a9de756c7de23179923371a2ee38629a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 10 Sep 2022 11:33:44 +0000 Subject: [PATCH 14/89] Prevent insta-stable no alloc shim support You will need to add the following as replacement for the old __rust_* definitions when not using the alloc shim. #[no_mangle] static __rust_no_alloc_shim_is_unstable: u8 = 0; --- src/allocator.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/allocator.rs b/src/allocator.rs index c27971897a0..d4b1ae2b613 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -5,7 +5,7 @@ use crate::prelude::*; use rustc_ast::expand::allocator::{ alloc_error_handler_name, default_fn_name, global_fn_name, AllocatorKind, AllocatorTy, - ALLOCATOR_METHODS, + ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE, }; use rustc_codegen_ssa::base::allocator_kind_for_codegen; use rustc_session::config::OomStrategy; @@ -94,4 +94,11 @@ fn codegen_inner( let val = oom_strategy.should_panic(); data_ctx.define(Box::new([val])); module.define_data(data_id, &data_ctx).unwrap(); + + let data_id = + module.declare_data(NO_ALLOC_SHIM_IS_UNSTABLE, Linkage::Export, false, false).unwrap(); + let mut data_ctx = DataContext::new(); + data_ctx.set_align(1); + data_ctx.define(Box::new([0])); + module.define_data(data_id, &data_ctx).unwrap(); } From 9b2a0984e9d6f8a89dc7dd154d26f4b518af4afd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 12 May 2023 12:50:44 +0000 Subject: [PATCH 15/89] Rustup to rustc 1.71.0-nightly (2a8221dbd 2023-05-11) --- build_sysroot/Cargo.lock | 8 ++++---- rust-toolchain | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 7755943bf3a..ad5381c88c9 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -106,9 +106,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.3" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ "compiler_builtins", "rustc-std-workspace-alloc", @@ -128,9 +128,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.142" +version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index 056268c61e6..83edc30874b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-05-05" +channel = "nightly-2023-05-12" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From f6ba10deadda0ed11fcee5db5084f9e08f5c7bbd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 12 May 2023 12:58:56 +0000 Subject: [PATCH 16/89] Fix rustc test suite --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 23792955462..312fa06b42d 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -74,6 +74,7 @@ rm -r tests/run-make/issue-64153 rm -r tests/run-make/codegen-options-parsing rm -r tests/run-make/lto-* rm -r tests/run-make/reproducible-build-2 +rm -r tests/run-make/issue-109934-lto-debuginfo # optimization tests # ================== From ecbb33a71b38498250bcc81b815331fbfde40736 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 12 May 2023 13:25:58 +0000 Subject: [PATCH 17/89] Implement and fix a couple more simd intrinsics --- scripts/test_rustc_tests.sh | 19 ++++++++-------- src/intrinsics/simd.rs | 45 +++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 312fa06b42d..7697571da95 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -36,6 +36,14 @@ rm tests/ui/parser/unclosed-delimiter-in-dep.rs # submodule contains //~ERROR # FIXME add needs-unwind to this test rm -r tests/run-make/libtest-junit +# extra warning about -Cpanic=abort for proc macros +rm tests/ui/proc-macro/crt-static.rs +rm tests/ui/proc-macro/proc-macro-deprecated-attr.rs +rm tests/ui/proc-macro/quote-debug.rs +rm tests/ui/proc-macro/no-missing-docs.rs +rm tests/ui/rust-2018/proc-macro-crate-in-paths.rs +rm tests/ui/proc-macro/allowed-signatures.rs + # vendor intrinsics rm tests/ui/sse2.rs # cpuid not supported, so sse2 not detected rm tests/ui/intrinsics/const-eval-select-x86_64.rs # requires x86_64 vendor intrinsics @@ -111,13 +119,6 @@ rm tests/ui/pattern/usefulness/doc-hidden-non-exhaustive.rs # same rm tests/ui/suggestions/derive-trait-for-method-call.rs # same rm tests/ui/typeck/issue-46112.rs # same -rm tests/ui/proc-macro/crt-static.rs # extra warning about -Cpanic=abort for proc macros -rm tests/ui/proc-macro/proc-macro-deprecated-attr.rs # same -rm tests/ui/proc-macro/quote-debug.rs # same -rm tests/ui/proc-macro/no-missing-docs.rs # same -rm tests/ui/rust-2018/proc-macro-crate-in-paths.rs # same -rm tests/ui/proc-macro/allowed-signatures.rs # same - # rustdoc-clif passes extra args, suppressing the help message when no args are passed rm -r tests/run-make/issue-88756-default-output @@ -132,9 +133,7 @@ rm -r tests/ui/consts/missing_span_in_backtrace.rs # expects sysroot source to b rm tests/incremental/spike-neg1.rs # errors out for some reason rm tests/incremental/spike-neg2.rs # same -rm tests/ui/simd/intrinsic/generic-reduction-pass.rs # simd_reduce_add_unordered doesn't accept an accumulator for integer vectors - -rm tests/ui/simd/simd-bitmask.rs # crash +rm tests/ui/simd/simd-bitmask.rs # simd_bitmask doesn't implement [u*; N] return type rm -r tests/run-make/issue-51671 # wrong filename given in case of --emit=obj rm -r tests/run-make/issue-30063 # same diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 5a038bfca5d..a0ccf291c42 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -488,7 +488,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }); } - sym::simd_reduce_add_ordered | sym::simd_reduce_add_unordered => { + sym::simd_reduce_add_ordered => { intrinsic_args!(fx, args => (v, acc); intrinsic); let acc = acc.load_scalar(fx); @@ -507,7 +507,25 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }); } - sym::simd_reduce_mul_ordered | sym::simd_reduce_mul_unordered => { + sym::simd_reduce_add_unordered => { + intrinsic_args!(fx, args => (v); intrinsic); + + // FIXME there must be no acc param for integer vectors + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + + simd_reduce(fx, v, None, ret, &|fx, lane_ty, a, b| { + if lane_ty.is_floating_point() { + fx.bcx.ins().fadd(a, b) + } else { + fx.bcx.ins().iadd(a, b) + } + }); + } + + sym::simd_reduce_mul_ordered => { intrinsic_args!(fx, args => (v, acc); intrinsic); let acc = acc.load_scalar(fx); @@ -526,6 +544,24 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }); } + sym::simd_reduce_mul_unordered => { + intrinsic_args!(fx, args => (v); intrinsic); + + // FIXME there must be no acc param for integer vectors + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + + simd_reduce(fx, v, None, ret, &|fx, lane_ty, a, b| { + if lane_ty.is_floating_point() { + fx.bcx.ins().fmul(a, b) + } else { + fx.bcx.ins().imul(a, b) + } + }); + } + sym::simd_reduce_all => { intrinsic_args!(fx, args => (v); intrinsic); @@ -581,7 +617,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( simd_reduce(fx, v, None, ret, &|fx, _ty, a, b| fx.bcx.ins().bxor(a, b)); } - sym::simd_reduce_min => { + sym::simd_reduce_min | sym::simd_reduce_min_nanless => { intrinsic_args!(fx, args => (v); intrinsic); if !v.layout().ty.is_simd() { @@ -600,7 +636,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }); } - sym::simd_reduce_max => { + sym::simd_reduce_max | sym::simd_reduce_max_nanless => { intrinsic_args!(fx, args => (v); intrinsic); if !v.layout().ty.is_simd() { @@ -878,6 +914,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( fx.tcx.sess.span_err(span, format!("Unknown SIMD intrinsic {}", intrinsic)); // Prevent verifier error fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + return; } } let ret_block = fx.get_block(target); From 899d193c9dc4d1dbe13698baf76c5368ad117b34 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 12 May 2023 17:07:31 +0000 Subject: [PATCH 18/89] Implement a couple more platform intrinsics --- scripts/test_rustc_tests.sh | 1 - src/intrinsics/simd.rs | 93 +++++++++++++++++++++++++++++++++---- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 7697571da95..9e5aefb7753 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -48,7 +48,6 @@ rm tests/ui/proc-macro/allowed-signatures.rs rm tests/ui/sse2.rs # cpuid not supported, so sse2 not detected rm tests/ui/intrinsics/const-eval-select-x86_64.rs # requires x86_64 vendor intrinsics rm tests/ui/simd/array-type.rs # "Index argument for `simd_insert` is not a constant" -rm tests/ui/simd/intrinsic/float-math-pass.rs # simd_fcos unimplemented # exotic linkages rm tests/ui/issues/issue-33992.rs # unsupported linkages diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index a0ccf291c42..6741362e8b6 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -434,8 +434,36 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }); } - sym::simd_round => { - intrinsic_args!(fx, args => (a); intrinsic); + sym::simd_fpow => { + intrinsic_args!(fx, args => (a, b); intrinsic); + + if !a.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty); + return; + } + + simd_pair_for_each_lane(fx, a, b, ret, &|fx, lane_ty, _ret_lane_ty, a_lane, b_lane| { + match lane_ty.kind() { + ty::Float(FloatTy::F32) => fx.lib_call( + "powf", + vec![AbiParam::new(types::F32), AbiParam::new(types::F32)], + vec![AbiParam::new(types::F32)], + &[a_lane, b_lane], + )[0], + ty::Float(FloatTy::F64) => fx.lib_call( + "pow", + vec![AbiParam::new(types::F64), AbiParam::new(types::F64)], + vec![AbiParam::new(types::F64)], + &[a_lane, b_lane], + )[0], + _ => unreachable!("{:?}", lane_ty), + } + }); + } + + sym::simd_fpowi => { + intrinsic_args!(fx, args => (a, exp); intrinsic); + let exp = exp.load_scalar(fx); if !a.layout().ty.is_simd() { report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty); @@ -448,22 +476,71 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( ret, &|fx, lane_ty, _ret_lane_ty, lane| match lane_ty.kind() { ty::Float(FloatTy::F32) => fx.lib_call( - "roundf", + "__powisf2", // compiler-builtins + vec![AbiParam::new(types::F32), AbiParam::new(types::I32)], vec![AbiParam::new(types::F32)], - vec![AbiParam::new(types::F32)], - &[lane], + &[lane, exp], )[0], ty::Float(FloatTy::F64) => fx.lib_call( - "round", + "__powidf2", // compiler-builtins + vec![AbiParam::new(types::F64), AbiParam::new(types::I32)], vec![AbiParam::new(types::F64)], - vec![AbiParam::new(types::F64)], - &[lane], + &[lane, exp], )[0], _ => unreachable!("{:?}", lane_ty), }, ); } + sym::simd_fsin + | sym::simd_fcos + | sym::simd_fexp + | sym::simd_fexp2 + | sym::simd_flog + | sym::simd_flog10 + | sym::simd_flog2 + | sym::simd_round => { + intrinsic_args!(fx, args => (a); intrinsic); + + if !a.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty); + return; + } + + simd_for_each_lane(fx, a, ret, &|fx, lane_ty, _ret_lane_ty, lane| { + let lane_ty = match lane_ty.kind() { + ty::Float(FloatTy::F32) => types::F32, + ty::Float(FloatTy::F64) => types::F64, + _ => unreachable!("{:?}", lane_ty), + }; + let name = match (intrinsic, lane_ty) { + (sym::simd_fsin, types::F32) => "sinf", + (sym::simd_fsin, types::F64) => "sin", + (sym::simd_fcos, types::F32) => "cosf", + (sym::simd_fcos, types::F64) => "cos", + (sym::simd_fexp, types::F32) => "expf", + (sym::simd_fexp, types::F64) => "exp", + (sym::simd_fexp2, types::F32) => "exp2f", + (sym::simd_fexp2, types::F64) => "exp2", + (sym::simd_flog, types::F32) => "logf", + (sym::simd_flog, types::F64) => "log", + (sym::simd_flog10, types::F32) => "log10f", + (sym::simd_flog10, types::F64) => "log10", + (sym::simd_flog2, types::F32) => "log2f", + (sym::simd_flog2, types::F64) => "log2", + (sym::simd_round, types::F32) => "roundf", + (sym::simd_round, types::F64) => "round", + _ => unreachable!("{:?}", intrinsic), + }; + fx.lib_call( + name, + vec![AbiParam::new(lane_ty)], + vec![AbiParam::new(lane_ty)], + &[lane], + )[0] + }); + } + sym::simd_fabs | sym::simd_fsqrt | sym::simd_ceil | sym::simd_floor | sym::simd_trunc => { intrinsic_args!(fx, args => (a); intrinsic); From e39191594f44667dc3dd602ed5de7485adb219ac Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 12 May 2023 17:07:38 +0000 Subject: [PATCH 19/89] Support _mm_movemask_ps --- scripts/test_rustc_tests.sh | 1 - src/intrinsics/llvm_x86.rs | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 9e5aefb7753..cb2211c7b1e 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -46,7 +46,6 @@ rm tests/ui/proc-macro/allowed-signatures.rs # vendor intrinsics rm tests/ui/sse2.rs # cpuid not supported, so sse2 not detected -rm tests/ui/intrinsics/const-eval-select-x86_64.rs # requires x86_64 vendor intrinsics rm tests/ui/simd/array-type.rs # "Index argument for `simd_insert` is not a constant" # exotic linkages diff --git a/src/intrinsics/llvm_x86.rs b/src/intrinsics/llvm_x86.rs index 56d8f13cec5..8b6f8ca672d 100644 --- a/src/intrinsics/llvm_x86.rs +++ b/src/intrinsics/llvm_x86.rs @@ -19,7 +19,10 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>( } // Used by `_mm_movemask_epi8` and `_mm256_movemask_epi8` - "llvm.x86.sse2.pmovmskb.128" | "llvm.x86.avx2.pmovmskb" | "llvm.x86.sse2.movmsk.pd" => { + "llvm.x86.sse2.pmovmskb.128" + | "llvm.x86.avx2.pmovmskb" + | "llvm.x86.sse.movmsk.ps" + | "llvm.x86.sse2.movmsk.pd" => { intrinsic_args!(fx, args => (a); intrinsic); let (lane_count, lane_ty) = a.layout().ty.simd_size_and_type(fx.tcx); From d2a8023948697ab07ed9ec08fb87588b858d9439 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 14 May 2023 10:17:12 +0000 Subject: [PATCH 20/89] Fix CirrusCI --- .cirrus.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 7886cae42a1..1405ea74903 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,9 +1,9 @@ task: name: freebsd freebsd_instance: - image: freebsd-13-1-release-amd64 + image: freebsd-13-2-release-amd64 setup_rust_script: - - pkg install -y curl git bash + - pkg install -y git bash - curl https://sh.rustup.rs -sSf --output rustup.sh - sh rustup.sh --default-toolchain none -y --profile=minimal target_cache: From 88ae8fc9c84a87d260157de72fe399d7e7e4a917 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 11 Feb 2023 13:13:38 +0000 Subject: [PATCH 21/89] Allow passing more than two commands to benchmark to hyperfine_command --- build_system/bench.rs | 8 +++++--- build_system/utils.rs | 5 ++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build_system/bench.rs b/build_system/bench.rs index a9a851d0a8a..978bac8cfe2 100644 --- a/build_system/bench.rs +++ b/build_system/bench.rs @@ -80,7 +80,7 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) { ); let bench_compile = - hyperfine_command(1, bench_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd); + hyperfine_command(1, bench_runs, Some(&clean_cmd), &[&llvm_build_cmd, &clif_build_cmd]); spawn_and_wait(bench_compile); @@ -95,8 +95,10 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) { 0, bench_runs, None, - Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(), - Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(), + &[ + Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(), + Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(), + ], ); bench_run.current_dir(RelPath::BUILD.to_path(dirs)); spawn_and_wait(bench_run); diff --git a/build_system/utils.rs b/build_system/utils.rs index abc5bab4942..8928ed7cd56 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -162,8 +162,7 @@ pub(crate) fn hyperfine_command( warmup: u64, runs: u64, prepare: Option<&str>, - a: &str, - b: &str, + cmds: &[&str], ) -> Command { let mut bench = Command::new("hyperfine"); @@ -179,7 +178,7 @@ pub(crate) fn hyperfine_command( bench.arg("--prepare").arg(prepare); } - bench.arg(a).arg(b); + bench.args(cmds); bench } From a43f08363e0983812fbbe68e8d91accf9496a1dd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 12 Feb 2023 13:10:24 +0000 Subject: [PATCH 22/89] Benchmark clif release builds with ./y.rs bench --- build_system/bench.rs | 62 +++++++++++++++---------------------------- build_system/mod.rs | 2 +- 2 files changed, 22 insertions(+), 42 deletions(-) diff --git a/build_system/bench.rs b/build_system/bench.rs index 978bac8cfe2..49f2954d57f 100644 --- a/build_system/bench.rs +++ b/build_system/bench.rs @@ -1,11 +1,10 @@ use std::env; -use std::fs; use std::path::Path; use super::path::{Dirs, RelPath}; use super::prepare::GitRepo; use super::rustc_info::get_file_name; -use super::utils::{hyperfine_command, spawn_and_wait, CargoProject, Compiler}; +use super::utils::{hyperfine_command, spawn_and_wait}; static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( "ebobby", @@ -14,18 +13,11 @@ static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( "", ); -// Use a separate target dir for the initial LLVM build to reduce unnecessary recompiles -static SIMPLE_RAYTRACER_LLVM: CargoProject = - CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer_llvm"); - -static SIMPLE_RAYTRACER: CargoProject = - CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer"); - -pub(crate) fn benchmark(dirs: &Dirs, bootstrap_host_compiler: &Compiler) { - benchmark_simple_raytracer(dirs, bootstrap_host_compiler); +pub(crate) fn benchmark(dirs: &Dirs) { + benchmark_simple_raytracer(dirs); } -fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) { +fn benchmark_simple_raytracer(dirs: &Dirs) { if std::process::Command::new("hyperfine").output().is_err() { eprintln!("Hyperfine not installed"); eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine"); @@ -34,33 +26,15 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) { if !SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).exists() { SIMPLE_RAYTRACER_REPO.fetch(dirs); - spawn_and_wait(SIMPLE_RAYTRACER.fetch( - &bootstrap_host_compiler.cargo, - &bootstrap_host_compiler.rustc, - dirs, - )); } - eprintln!("[LLVM BUILD] simple-raytracer"); - let build_cmd = SIMPLE_RAYTRACER_LLVM.build(bootstrap_host_compiler, dirs); - spawn_and_wait(build_cmd); - fs::copy( - SIMPLE_RAYTRACER_LLVM - .target_dir(dirs) - .join(&bootstrap_host_compiler.triple) - .join("debug") - .join(get_file_name("main", "bin")), - RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_llvm", "bin")), - ) - .unwrap(); - let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap(); eprintln!("[BENCH COMPILE] ebobby/simple-raytracer"); let cargo_clif = RelPath::DIST.to_path(dirs).join(get_file_name("cargo_clif", "bin").replace('_', "-")); - let manifest_path = SIMPLE_RAYTRACER.manifest_path(dirs); - let target_dir = SIMPLE_RAYTRACER.target_dir(dirs); + let manifest_path = SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).join("Cargo.toml"); + let target_dir = RelPath::BUILD.join("simple_raytracer").to_path(dirs); let clean_cmd = format!( "RUSTC=rustc cargo clean --manifest-path {manifest_path} --target-dir {target_dir}", @@ -68,28 +42,33 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) { target_dir = target_dir.display(), ); let llvm_build_cmd = format!( - "RUSTC=rustc cargo build --manifest-path {manifest_path} --target-dir {target_dir}", + "RUSTC=rustc cargo build --manifest-path {manifest_path} --target-dir {target_dir} && (rm build/raytracer_cg_llvm || true) && ln build/simple_raytracer/debug/main build/raytracer_cg_llvm", manifest_path = manifest_path.display(), target_dir = target_dir.display(), ); let clif_build_cmd = format!( - "RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}", + "RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} && (rm build/raytracer_cg_clif || true) && ln build/simple_raytracer/debug/main build/raytracer_cg_clif", + cargo_clif = cargo_clif.display(), + manifest_path = manifest_path.display(), + target_dir = target_dir.display(), + ); + let clif_build_opt_cmd = format!( + "RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} --release && (rm build/raytracer_cg_clif_opt || true) && ln build/simple_raytracer/release/main build/raytracer_cg_clif_opt", cargo_clif = cargo_clif.display(), manifest_path = manifest_path.display(), target_dir = target_dir.display(), ); - let bench_compile = - hyperfine_command(1, bench_runs, Some(&clean_cmd), &[&llvm_build_cmd, &clif_build_cmd]); + let bench_compile = hyperfine_command( + 1, + bench_runs, + Some(&clean_cmd), + &[&llvm_build_cmd, &clif_build_cmd, &clif_build_opt_cmd], + ); spawn_and_wait(bench_compile); eprintln!("[BENCH RUN] ebobby/simple-raytracer"); - fs::copy( - target_dir.join("debug").join(get_file_name("main", "bin")), - RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_clif", "bin")), - ) - .unwrap(); let mut bench_run = hyperfine_command( 0, @@ -98,6 +77,7 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) { &[ Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(), Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(), + Path::new(".").join(get_file_name("raytracer_cg_clif_opt", "bin")).to_str().unwrap(), ], ); bench_run.current_dir(RelPath::BUILD.to_path(dirs)); diff --git a/build_system/mod.rs b/build_system/mod.rs index e4ed9be23b7..b3293486c13 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -187,7 +187,7 @@ pub(crate) fn main() { &bootstrap_host_compiler, target_triple, ); - bench::benchmark(&dirs, &bootstrap_host_compiler); + bench::benchmark(&dirs); } } } From 521d9371160e7055b2ee4a6ece6921091de3ba1c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 17 Apr 2023 09:32:07 +0000 Subject: [PATCH 23/89] Pass --cap-lints=allow to tests --- build_system/tests.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build_system/tests.rs b/build_system/tests.rs index 0c25b4aadfa..3af74e1e97c 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -245,7 +245,7 @@ pub(crate) fn run_tests( let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot"); if run_base_sysroot || run_extended_sysroot { - let target_compiler = build_sysroot::build_sysroot( + let mut target_compiler = build_sysroot::build_sysroot( dirs, channel, sysroot_kind, @@ -253,6 +253,9 @@ pub(crate) fn run_tests( bootstrap_host_compiler, target_triple.clone(), ); + // Rust's build system denies a couple of lints that trigger on several of the test + // projects. Changing the code to fix them is not worth it, so just silence all lints. + target_compiler.rustflags += " --cap-lints=allow"; let runner = TestRunner::new( dirs.clone(), From b773282309ab910ae1d823015b637d6d15ea40fa Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 15 Feb 2023 18:25:18 +0000 Subject: [PATCH 24/89] Use --sysroot ... instead of --sysroot=... Rust's build system doesn't handle --sysroot=... correctly --- build_system/build_sysroot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 76b602fe719..d6e231c53b5 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -240,7 +240,7 @@ fn build_clif_sysroot_for_triple( rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap())); // Necessary for MinGW to find rsbegin.o and rsend.o rustflags - .push_str(&format!(" --sysroot={}", RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap())); + .push_str(&format!(" --sysroot {}", RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap())); if channel == "release" { rustflags.push_str(" -Zmir-opt-level=3"); } From 8a9b38fd3bbf9d57cddb824f104fad592c7377e0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 16 May 2023 16:04:03 +1000 Subject: [PATCH 25/89] Avoid `&format("...")` calls in error message code. Error message all end up passing into a function as an `impl Into<{D,Subd}iagnosticMessage>`. If an error message is creatd as `&format("...")` that means we allocate a string (in the `format!` call), then take a reference, and then clone (allocating again) the reference to produce the `{D,Subd}iagnosticMessage`, which is silly. This commit removes the leading `&` from a lot of these cases. This means the original `String` is moved into the `{D,Subd}iagnosticMessage`, avoiding the double allocations. This requires changing some function argument types from `&str` to `String` (when all arguments are `String`) or `impl Into<{D,Subd}iagnosticMessage>` (when some arguments are `String` and some are `&str`). --- src/pretty_clif.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 27e21183c55..1007b33eca4 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -227,7 +227,7 @@ pub(crate) fn write_ir_file( // Using early_warn as no Session is available here rustc_session::early_warn( rustc_session::config::ErrorOutputType::default(), - &format!("error writing ir file: {}", err), + format!("error writing ir file: {}", err), ); } } From 74ab27c26930e8697b25a0938305b722fc080567 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Tue, 16 May 2023 19:23:38 +0200 Subject: [PATCH 26/89] Remove `LangItems::require` It's just a short wrapper used by `tcx.require_lang_item`. Deleting it gives us a negative diff. --- src/base.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/base.rs b/src/base.rs index e9dbea1be67..25fd5ca3ae8 100644 --- a/src/base.rs +++ b/src/base.rs @@ -966,11 +966,7 @@ fn codegen_panic_inner<'tcx>( args: &[Value], span: Span, ) { - let def_id = fx - .tcx - .lang_items() - .require(lang_item) - .unwrap_or_else(|e| fx.tcx.sess.span_fatal(span, e.to_string())); + let def_id = fx.tcx.require_lang_item(lang_item, Some(span)); let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx); let symbol_name = fx.tcx.symbol_name(instance).name; From 6900c9943d7b43692da6e54cb07821ea48fa8804 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 29 Apr 2023 11:43:41 +0000 Subject: [PATCH 27/89] Update Cranelift to 0.96.0 --- Cargo.lock | 131 +++++++++++++++++++++++++---------------------- Cargo.toml | 12 ++--- src/allocator.rs | 8 +-- src/common.rs | 6 +-- src/constant.rs | 30 +++++------ src/lib.rs | 2 +- 6 files changed, 100 insertions(+), 89 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d25bc52caa0..ee987207532 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,12 @@ version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" +[[package]] +name = "arbitrary" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d098ff73c1ca148721f37baad5ea6a465a13f9573aba8641fbbbae8164a54e" + [[package]] name = "autocfg" version = "1.1.0" @@ -37,12 +43,6 @@ version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - [[package]] name = "cfg-if" version = "1.0.0" @@ -51,23 +51,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.95.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1277fbfa94bc82c8ec4af2ded3e639d49ca5f7f3c7eeab2c66accd135ece4e70" +checksum = "5dfbfa12cfd843d39182f3e466b3b1a2b53ff348b34eb3579fcd4ee818d177a9" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.95.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6e8c31ad3b2270e9aeec38723888fe1b0ace3bea2b06b3f749ccf46661d3220" +checksum = "a3efdd75f82d338ebce8f6e492fac7205e4b1091bb76da74ad27894b224052c5" dependencies = [ "bumpalo", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", + "cranelift-control", "cranelift-entity", "cranelift-isle", "gimli", @@ -80,30 +81,39 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.95.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8ac5ac30d62b2d66f12651f6b606dbdfd9c2cfd0908de6b387560a277c5c9da" +checksum = "e03ccd2e7959cb8c1434aeda5a80599a65f71ba75e00bf969d5f8e2dc7ca11d3" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.95.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd82b8b376247834b59ed9bdc0ddeb50f517452827d4a11bccf5937b213748b8" +checksum = "e6e64284ccb56442849500cf17a8cc3681a254ec1bb8f0c887f55b2f81beab70" + +[[package]] +name = "cranelift-control" +version = "0.96.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "537278bd7c9389b6d820d0b8f549460445d8e1cb1d21b617ac2e44aaf2f686cf" +dependencies = [ + "arbitrary", +] [[package]] name = "cranelift-entity" -version = "0.95.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40099d38061b37e505e63f89bab52199037a72b931ad4868d9089ff7268660b0" +checksum = "2e234fff84b1941dd25fa3e24c466283256b377997ccbd85f592066389251796" [[package]] name = "cranelift-frontend" -version = "0.95.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a25d9d0a0ae3079c463c34115ec59507b4707175454f0eee0891e83e30e82d" +checksum = "59ebfb3cc39ef246aecc9bbd44f6259501cf243da19d45888409cb7f06a34bd0" dependencies = [ "cranelift-codegen", "log", @@ -113,18 +123,19 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.95.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80de6a7d0486e4acbd5f9f87ec49912bf4c8fb6aea00087b989685460d4469ba" +checksum = "f22fdc6c4ce755b44f92f2e3e1f7f1138f9ee5c3d99e2e2b20418475713a2c6c" [[package]] name = "cranelift-jit" -version = "0.95.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ca96b05988aa057eda09a817a6e31915fabd7f476b513123aff08053cd193dd" +checksum = "65b7970f8950043cada68dcb8b1e9ea5f00d9b7aaf8cb139b4954fd4fb365bc2" dependencies = [ "anyhow", "cranelift-codegen", + "cranelift-control", "cranelift-entity", "cranelift-module", "cranelift-native", @@ -138,19 +149,20 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.95.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5112c0be9cc5da064e0620570d67852f11ce44f2e572a58ecf7f11df73978b8" +checksum = "1413dae1da005e5f54b185b0173f13b4184cd4d80ec3cc8c37ee5666c20a9ccb" dependencies = [ "anyhow", "cranelift-codegen", + "cranelift-control", ] [[package]] name = "cranelift-native" -version = "0.95.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6b03e0e03801c4b3fd8ce0758a94750c07a44e7944cc0ffbf0d3f2e7c79b00" +checksum = "e961c2eba1af0ec7422170fc1ba635d06000f466ee4d4811f3d4cd6f4594327f" dependencies = [ "cranelift-codegen", "libc", @@ -159,12 +171,13 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.95.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48ed1b37d0972abe804cb5bf2b35f3a76a276ebbe148e3a726d8e31042790978" +checksum = "b1521f1e47b81d913f032e8ab246c2c8201c6da9fd7dcef6afee07d2afa31811" dependencies = [ "anyhow", "cranelift-codegen", + "cranelift-control", "cranelift-module", "log", "object", @@ -186,15 +199,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "gimli" version = "0.27.2" @@ -291,12 +295,13 @@ checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "regalloc2" -version = "0.6.1" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80535183cae11b149d618fbd3c37e38d7cda589d82d7769e196ca9a9042d7621" +checksum = "d4a52e724646c6c0800fc456ec43b4165d2f91fba88ceaca06d9e0b400023478" dependencies = [ - "fxhash", + "hashbrown 0.13.2", "log", + "rustc-hash", "slice-group-by", "smallvec", ] @@ -313,6 +318,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc_codegen_cranelift" version = "0.1.0" @@ -363,9 +374,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasmtime-jit-icache-coherence" -version = "8.0.1" +version = "9.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aecae978b13f7f67efb23bd827373ace4578f2137ec110bbf6a4a7cde4121bbd" +checksum = "cc60ec61519028279b9e8b6119a52c23b7ce2f2a8f0ec3cbe12aeb6ee9b2c549" dependencies = [ "cfg-if", "libc", @@ -396,18 +407,18 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" -version = "0.45.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -420,42 +431,42 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/Cargo.toml b/Cargo.toml index 85b9c0a8464..141d7cb8e1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,12 +15,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.95.1", features = ["unwind", "all-arch"] } -cranelift-frontend = { version = "0.95.1" } -cranelift-module = { version = "0.95.1" } -cranelift-native = { version = "0.95.1" } -cranelift-jit = { version = "0.95.1", optional = true } -cranelift-object = { version = "0.95.1" } +cranelift-codegen = { version = "0.96", features = ["unwind", "all-arch"] } +cranelift-frontend = { version = "0.96" } +cranelift-module = { version = "0.96" } +cranelift-native = { version = "0.96" } +cranelift-jit = { version = "0.96", optional = true } +cranelift-object = { version = "0.96" } target-lexicon = "0.12.0" gimli = { version = "0.27.2", default-features = false, features = ["write"]} object = { version = "0.30.3", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } diff --git a/src/allocator.rs b/src/allocator.rs index 2c246ceb37d..40ec4b32ac2 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -85,9 +85,9 @@ fn codegen_inner( ); let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap(); - let mut data_ctx = DataContext::new(); - data_ctx.set_align(1); + let mut data = DataDescription::new(); + data.set_align(1); let val = oom_strategy.should_panic(); - data_ctx.define(Box::new([val])); - module.define_data(data_id, &data_ctx).unwrap(); + data.define(Box::new([val])); + module.define_data(data_id, &data).unwrap(); } diff --git a/src/common.rs b/src/common.rs index ccb3a0c4f27..0aeb41b8a3e 100644 --- a/src/common.rs +++ b/src/common.rs @@ -458,12 +458,12 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { } pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value { - let mut data_ctx = DataContext::new(); - data_ctx.define(msg.as_bytes().to_vec().into_boxed_slice()); + let mut data = DataDescription::new(); + data.define(msg.as_bytes().to_vec().into_boxed_slice()); let msg_id = self.module.declare_anonymous_data(false, false).unwrap(); // Ignore DuplicateDefinition error, as the data will be the same - let _ = self.module.define_data(msg_id, &data_ctx); + let _ = self.module.define_data(msg_id, &data); let local_msg_id = self.module.declare_data_in_func(msg_id, self.bcx.func); if self.clif_comments.enabled() { diff --git a/src/constant.rs b/src/constant.rs index 77af561a587..427340c333e 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -324,12 +324,12 @@ fn data_id_for_static( let ref_name = format!("_rust_extern_with_linkage_{}", symbol_name); let ref_data_id = module.declare_data(&ref_name, Linkage::Local, false, false).unwrap(); - let mut data_ctx = DataContext::new(); - data_ctx.set_align(align); - let data = module.declare_data_in_data(data_id, &mut data_ctx); - data_ctx.define(std::iter::repeat(0).take(pointer_ty(tcx).bytes() as usize).collect()); - data_ctx.write_data_addr(0, data, 0); - match module.define_data(ref_data_id, &data_ctx) { + let mut data = DataDescription::new(); + data.set_align(align); + let data_gv = module.declare_data_in_data(data_id, &mut data); + data.define(std::iter::repeat(0).take(pointer_ty(tcx).bytes() as usize).collect()); + data.write_data_addr(0, data_gv, 0); + match module.define_data(ref_data_id, &data) { // Every time the static is referenced there will be another definition of this global, // so duplicate definitions are expected and allowed. Err(ModuleError::DuplicateDefinition(_)) => {} @@ -394,9 +394,9 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant continue; } - let mut data_ctx = DataContext::new(); + let mut data = DataDescription::new(); let alloc = alloc.inner(); - data_ctx.set_align(alloc.align.bytes()); + data.set_align(alloc.align.bytes()); if let Some(section_name) = section_name { let (segment_name, section_name) = if tcx.sess.target.is_like_osx { @@ -412,11 +412,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant } else { ("", section_name.as_str()) }; - data_ctx.set_segment_section(segment_name, section_name); + data.set_segment_section(segment_name, section_name); } let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec(); - data_ctx.define(bytes.into_boxed_slice()); + data.define(bytes.into_boxed_slice()); for &(offset, alloc_id) in alloc.provenance().ptrs().iter() { let addend = { @@ -435,8 +435,8 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant assert_eq!(addend, 0); let func_id = crate::abi::import_function(tcx, module, instance.polymorphize(tcx)); - let local_func_id = module.declare_func_in_data(func_id, &mut data_ctx); - data_ctx.write_function_addr(offset.bytes() as u32, local_func_id); + let local_func_id = module.declare_func_in_data(func_id, &mut data); + data.write_function_addr(offset.bytes() as u32, local_func_id); continue; } GlobalAlloc::Memory(target_alloc) => { @@ -462,11 +462,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant } }; - let global_value = module.declare_data_in_data(data_id, &mut data_ctx); - data_ctx.write_data_addr(offset.bytes() as u32, global_value, addend as i64); + let global_value = module.declare_data_in_data(data_id, &mut data); + data.write_data_addr(offset.bytes() as u32, global_value, addend as i64); } - module.define_data(data_id, &data_ctx).unwrap(); + module.define_data(data_id, &data).unwrap(); cx.done.insert(data_id); } diff --git a/src/lib.rs b/src/lib.rs index 9966cc2ef3c..5ff784f3dd7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,7 +102,7 @@ mod prelude { pub(crate) use cranelift_codegen::isa::{self, CallConv}; pub(crate) use cranelift_codegen::Context; pub(crate) use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; - pub(crate) use cranelift_module::{self, DataContext, FuncId, Linkage, Module}; + pub(crate) use cranelift_module::{self, DataDescription, FuncId, Linkage, Module}; pub(crate) use crate::abi::*; pub(crate) use crate::base::{codegen_operand, codegen_place}; From de8a4d5d46f6f270ea35192a03d701230d0552e8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 10 Feb 2023 09:45:50 +0000 Subject: [PATCH 28/89] Remove all implicit "rustc" from rustc_info.rs --- build_system/bench.rs | 28 +++++++++++++++++++--------- build_system/build_backend.rs | 2 +- build_system/build_sysroot.rs | 2 +- build_system/mod.rs | 6 +++--- build_system/rustc_info.rs | 8 ++++---- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/build_system/bench.rs b/build_system/bench.rs index 49f2954d57f..d24803eb7c6 100644 --- a/build_system/bench.rs +++ b/build_system/bench.rs @@ -4,7 +4,7 @@ use std::path::Path; use super::path::{Dirs, RelPath}; use super::prepare::GitRepo; use super::rustc_info::get_file_name; -use super::utils::{hyperfine_command, spawn_and_wait}; +use super::utils::{hyperfine_command, spawn_and_wait, Compiler}; static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( "ebobby", @@ -13,11 +13,11 @@ static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( "", ); -pub(crate) fn benchmark(dirs: &Dirs) { - benchmark_simple_raytracer(dirs); +pub(crate) fn benchmark(dirs: &Dirs, bootstrap_host_compiler: &Compiler) { + benchmark_simple_raytracer(dirs, bootstrap_host_compiler); } -fn benchmark_simple_raytracer(dirs: &Dirs) { +fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) { if std::process::Command::new("hyperfine").output().is_err() { eprintln!("Hyperfine not installed"); eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine"); @@ -31,8 +31,9 @@ fn benchmark_simple_raytracer(dirs: &Dirs) { let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap(); eprintln!("[BENCH COMPILE] ebobby/simple-raytracer"); - let cargo_clif = - RelPath::DIST.to_path(dirs).join(get_file_name("cargo_clif", "bin").replace('_', "-")); + let cargo_clif = RelPath::DIST + .to_path(dirs) + .join(get_file_name(&bootstrap_host_compiler.rustc, "cargo_clif", "bin").replace('_', "-")); let manifest_path = SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).join("Cargo.toml"); let target_dir = RelPath::BUILD.join("simple_raytracer").to_path(dirs); @@ -75,9 +76,18 @@ fn benchmark_simple_raytracer(dirs: &Dirs) { bench_runs, None, &[ - Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(), - Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(), - Path::new(".").join(get_file_name("raytracer_cg_clif_opt", "bin")).to_str().unwrap(), + Path::new(".") + .join(get_file_name(&bootstrap_host_compiler.rustc, "raytracer_cg_llvm", "bin")) + .to_str() + .unwrap(), + Path::new(".") + .join(get_file_name(&bootstrap_host_compiler.rustc, "raytracer_cg_clif", "bin")) + .to_str() + .unwrap(), + Path::new(".") + .join(get_file_name(&bootstrap_host_compiler.rustc, "raytracer_cg_clif_opt", "bin")) + .to_str() + .unwrap(), ], ); bench_run.current_dir(RelPath::BUILD.to_path(dirs)); diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 4b740fa2db6..fc0965999e3 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -52,5 +52,5 @@ pub(crate) fn build_backend( .target_dir(dirs) .join(&bootstrap_host_compiler.triple) .join(channel) - .join(get_file_name("rustc_codegen_cranelift", "dylib")) + .join(get_file_name(&bootstrap_host_compiler.rustc, "rustc_codegen_cranelift", "dylib")) } diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index d6e231c53b5..67c4cfa4417 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -40,7 +40,7 @@ pub(crate) fn build_sysroot( try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path); // Build and copy rustc and cargo wrappers - let wrapper_base_name = get_file_name("____", "bin"); + let wrapper_base_name = get_file_name(&bootstrap_host_compiler.rustc, "____", "bin"); let toolchain_name = get_toolchain_name(); for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] { let wrapper_name = wrapper_base_name.replace("____", wrapper); diff --git a/build_system/mod.rs b/build_system/mod.rs index b3293486c13..0a83ea93778 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -1,5 +1,5 @@ use std::env; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process; use self::utils::{is_ci, is_ci_opt, Compiler}; @@ -105,7 +105,7 @@ pub(crate) fn main() { std::env::var("HOST_TRIPLE") .ok() .or_else(|| config::get_value("host")) - .unwrap_or_else(|| rustc_info::get_host_triple()), + .unwrap_or_else(|| rustc_info::get_host_triple(Path::new("rustc"))), ); let target_triple = std::env::var("TARGET_TRIPLE") .ok() @@ -187,7 +187,7 @@ pub(crate) fn main() { &bootstrap_host_compiler, target_triple, ); - bench::benchmark(&dirs); + bench::benchmark(&dirs, &bootstrap_host_compiler); } } } diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index a70453b4422..63f41ad5662 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -7,9 +7,9 @@ pub(crate) fn get_rustc_version(rustc: &Path) -> String { String::from_utf8(version_info).unwrap() } -pub(crate) fn get_host_triple() -> String { +pub(crate) fn get_host_triple(rustc: &Path) -> String { let version_info = - Command::new("rustc").stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout; + Command::new(rustc).stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout; String::from_utf8(version_info) .unwrap() .lines() @@ -73,8 +73,8 @@ pub(crate) fn get_default_sysroot(rustc: &Path) -> PathBuf { Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned() } -pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String { - let file_name = Command::new("rustc") +pub(crate) fn get_file_name(rustc: &Path, crate_name: &str, crate_type: &str) -> String { + let file_name = Command::new(rustc) .stderr(Stdio::inherit()) .args(&[ "--crate-name", From 2155c0350081ae159e37aa25cfd829da950bb282 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 10 Feb 2023 10:03:42 +0000 Subject: [PATCH 29/89] Inline Compiler::bootstrap_with_triple --- build_system/mod.rs | 22 +++++++++++++++++----- build_system/utils.rs | 13 ------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/build_system/mod.rs b/build_system/mod.rs index 0a83ea93778..80a777fc00e 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -1,5 +1,5 @@ use std::env; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::process; use self::utils::{is_ci, is_ci_opt, Compiler}; @@ -101,12 +101,24 @@ pub(crate) fn main() { } } - let bootstrap_host_compiler = Compiler::bootstrap_with_triple( - std::env::var("HOST_TRIPLE") + let bootstrap_host_compiler = { + let cargo = rustc_info::get_cargo_path(); + let rustc = rustc_info::get_rustc_path(); + let rustdoc = rustc_info::get_rustdoc_path(); + let triple = std::env::var("HOST_TRIPLE") .ok() .or_else(|| config::get_value("host")) - .unwrap_or_else(|| rustc_info::get_host_triple(Path::new("rustc"))), - ); + .unwrap_or_else(|| rustc_info::get_host_triple(&rustc)); + Compiler { + cargo, + rustc, + rustdoc, + rustflags: String::new(), + rustdocflags: String::new(), + triple, + runner: vec![], + } + }; let target_triple = std::env::var("TARGET_TRIPLE") .ok() .or_else(|| config::get_value("target")) diff --git a/build_system/utils.rs b/build_system/utils.rs index 8928ed7cd56..6c0ecd8b02a 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -5,7 +5,6 @@ use std::path::{Path, PathBuf}; use std::process::{self, Command, Stdio}; use super::path::{Dirs, RelPath}; -use super::rustc_info::{get_cargo_path, get_rustc_path, get_rustdoc_path}; #[derive(Clone, Debug)] pub(crate) struct Compiler { @@ -19,18 +18,6 @@ pub(crate) struct Compiler { } impl Compiler { - pub(crate) fn bootstrap_with_triple(triple: String) -> Compiler { - Compiler { - cargo: get_cargo_path(), - rustc: get_rustc_path(), - rustdoc: get_rustdoc_path(), - rustflags: String::new(), - rustdocflags: String::new(), - triple, - runner: vec![], - } - } - pub(crate) fn set_cross_linker_and_runner(&mut self) { match self.triple.as_str() { "aarch64-unknown-linux-gnu" => { From b1d8b7186ccee2ef57886dc3bf17225d11a3935f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:16:48 +0000 Subject: [PATCH 30/89] Only pass --frozen to cargo when it is passed to y.rs --- build_system/abi_cafe.rs | 1 - build_system/mod.rs | 3 +++ build_system/path.rs | 1 + build_system/prepare.rs | 8 -------- build_system/usage.txt | 11 +++++++---- build_system/utils.rs | 24 +++++------------------- 6 files changed, 16 insertions(+), 32 deletions(-) diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index 0da27f529b3..5b49a2e01d0 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -19,7 +19,6 @@ pub(crate) fn run( bootstrap_host_compiler: &Compiler, ) { ABI_CAFE_REPO.fetch(dirs); - spawn_and_wait(ABI_CAFE.fetch("cargo", &bootstrap_host_compiler.rustc, dirs)); eprintln!("Building sysroot for abi-cafe"); build_sysroot::build_sysroot( diff --git a/build_system/mod.rs b/build_system/mod.rs index 80a777fc00e..2f8550dbf0e 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -78,6 +78,7 @@ pub(crate) fn main() { let mut channel = "release"; let mut sysroot_kind = SysrootKind::Clif; let mut use_unstable_features = true; + let mut frozen = false; while let Some(arg) = args.next().as_deref() { match arg { "--out-dir" => { @@ -96,6 +97,7 @@ pub(crate) fn main() { } } "--no-unstable-features" => use_unstable_features = false, + "--frozen" => frozen = true, flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag), arg => arg_error!("Unexpected argument {}", arg), } @@ -132,6 +134,7 @@ pub(crate) fn main() { download_dir: out_dir.join("download"), build_dir: out_dir.join("build"), dist_dir: out_dir.join("dist"), + frozen, }; path::RelPath::BUILD.ensure_exists(&dirs); diff --git a/build_system/path.rs b/build_system/path.rs index 3290723005d..4f86c0fd29d 100644 --- a/build_system/path.rs +++ b/build_system/path.rs @@ -9,6 +9,7 @@ pub(crate) struct Dirs { pub(crate) download_dir: PathBuf, pub(crate) build_dir: PathBuf, pub(crate) dist_dir: PathBuf, + pub(crate) frozen: bool, } #[doc(hidden)] diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 6769e42d44b..2754b167850 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -12,20 +12,12 @@ use super::utils::{copy_dir_recursively, git_command, retry_spawn_and_wait, spaw pub(crate) fn prepare(dirs: &Dirs) { RelPath::DOWNLOAD.ensure_fresh(dirs); - spawn_and_wait(super::build_backend::CG_CLIF.fetch("cargo", "rustc", dirs)); - prepare_stdlib(dirs); - spawn_and_wait(super::build_sysroot::STANDARD_LIBRARY.fetch("cargo", "rustc", dirs)); - prepare_coretests(dirs); - spawn_and_wait(super::tests::LIBCORE_TESTS.fetch("cargo", "rustc", dirs)); super::tests::RAND_REPO.fetch(dirs); - spawn_and_wait(super::tests::RAND.fetch("cargo", "rustc", dirs)); super::tests::REGEX_REPO.fetch(dirs); - spawn_and_wait(super::tests::REGEX.fetch("cargo", "rustc", dirs)); super::tests::PORTABLE_SIMD_REPO.fetch(dirs); - spawn_and_wait(super::tests::PORTABLE_SIMD.fetch("cargo", "rustc", dirs)); } fn prepare_stdlib(dirs: &Dirs) { diff --git a/build_system/usage.txt b/build_system/usage.txt index ab98ccc35a5..e7b4f0af2d9 100644 --- a/build_system/usage.txt +++ b/build_system/usage.txt @@ -2,10 +2,10 @@ The build system of cg_clif. USAGE: ./y.rs prepare [--out-dir DIR] - ./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] - ./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] - ./y.rs abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] - ./y.rs bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] + ./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] [--frozen] + ./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] [--frozen] + ./y.rs abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] [--frozen] + ./y.rs bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] [--frozen] OPTIONS: --debug @@ -26,6 +26,9 @@ OPTIONS: Some features are not yet ready for production usage. This option will disable these features. This includes the JIT mode and inline assembly support. + --frozen + Require Cargo.lock and cache are up to date + REQUIREMENTS: * Rustup: The build system has a hard coded dependency on rustup to install the right nightly version and make sure it is used where necessary. diff --git a/build_system/utils.rs b/build_system/utils.rs index 6c0ecd8b02a..3e12ed22ef6 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -81,8 +81,11 @@ impl CargoProject { .arg("--manifest-path") .arg(self.manifest_path(dirs)) .arg("--target-dir") - .arg(self.target_dir(dirs)) - .arg("--frozen"); + .arg(self.target_dir(dirs)); + + if dirs.frozen { + cmd.arg("--frozen"); + } cmd } @@ -107,23 +110,6 @@ impl CargoProject { cmd } - #[must_use] - pub(crate) fn fetch( - &self, - cargo: impl AsRef, - rustc: impl AsRef, - dirs: &Dirs, - ) -> Command { - let mut cmd = Command::new(cargo.as_ref()); - - cmd.env("RUSTC", rustc.as_ref()) - .arg("fetch") - .arg("--manifest-path") - .arg(self.manifest_path(dirs)); - - cmd - } - pub(crate) fn clean(&self, dirs: &Dirs) { let _ = fs::remove_dir_all(self.target_dir(dirs)); } From 22befab611db45f5448d09db63e67fb72bd9af0c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:28:09 +0000 Subject: [PATCH 31/89] Avoid hard-coding rustc path in prepare.rs --- build_system/mod.rs | 2 +- build_system/prepare.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/build_system/mod.rs b/build_system/mod.rs index 2f8550dbf0e..58b21f64d37 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -149,7 +149,7 @@ pub(crate) fn main() { } if command == Command::Prepare { - prepare::prepare(&dirs); + prepare::prepare(&dirs, &bootstrap_host_compiler.rustc); process::exit(0); } diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 2754b167850..ac2dc47dd7f 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -9,19 +9,19 @@ use super::rustc_info::{get_default_sysroot, get_rustc_version}; use super::tests::LIBCORE_TESTS_SRC; use super::utils::{copy_dir_recursively, git_command, retry_spawn_and_wait, spawn_and_wait}; -pub(crate) fn prepare(dirs: &Dirs) { +pub(crate) fn prepare(dirs: &Dirs, rustc: &Path) { RelPath::DOWNLOAD.ensure_fresh(dirs); - prepare_stdlib(dirs); - prepare_coretests(dirs); + prepare_stdlib(dirs, rustc); + prepare_coretests(dirs, rustc); super::tests::RAND_REPO.fetch(dirs); super::tests::REGEX_REPO.fetch(dirs); super::tests::PORTABLE_SIMD_REPO.fetch(dirs); } -fn prepare_stdlib(dirs: &Dirs) { - let sysroot_src_orig = get_default_sysroot(Path::new("rustc")).join("lib/rustlib/src/rust"); +fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { + let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust"); assert!(sysroot_src_orig.exists()); eprintln!("[COPY] stdlib src"); @@ -36,7 +36,7 @@ fn prepare_stdlib(dirs: &Dirs) { &SYSROOT_SRC.to_path(dirs).join("library"), ); - let rustc_version = get_rustc_version(Path::new("rustc")); + let rustc_version = get_rustc_version(rustc); fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap(); eprintln!("[GIT] init"); @@ -45,8 +45,8 @@ fn prepare_stdlib(dirs: &Dirs) { apply_patches(dirs, "stdlib", &SYSROOT_SRC.to_path(dirs)); } -fn prepare_coretests(dirs: &Dirs) { - let sysroot_src_orig = get_default_sysroot(Path::new("rustc")).join("lib/rustlib/src/rust"); +fn prepare_coretests(dirs: &Dirs, rustc: &Path) { + let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust"); assert!(sysroot_src_orig.exists()); eprintln!("[COPY] coretests src"); From a2f720d9fe12a0981a14fd16f84cb8b23c284432 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 13 Feb 2023 10:11:45 +0000 Subject: [PATCH 32/89] Allow building and testing without rustup This can be done by installing the nightly specified in rust-toolchain.toml and then pointing the CARGO, RUSTC and RUSTDOC env vars to the right executables. --- build_system/abi_cafe.rs | 2 ++ build_system/build_sysroot.rs | 18 +++++++++++++++--- build_system/mod.rs | 20 +++++++++++++++++++- build_system/rustc_info.rs | 9 +++++++++ build_system/tests.rs | 3 +++ build_system/usage.txt | 5 +++-- scripts/cargo-clif.rs | 13 +++++++++---- scripts/rustc-clif.rs | 13 +++++++++---- scripts/rustdoc-clif.rs | 13 +++++++++---- 9 files changed, 78 insertions(+), 18 deletions(-) diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index 5b49a2e01d0..8ffd4852083 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -16,6 +16,7 @@ pub(crate) fn run( sysroot_kind: SysrootKind, dirs: &Dirs, cg_clif_dylib: &Path, + rustup_toolchain_name: Option<&str>, bootstrap_host_compiler: &Compiler, ) { ABI_CAFE_REPO.fetch(dirs); @@ -27,6 +28,7 @@ pub(crate) fn run( sysroot_kind, cg_clif_dylib, bootstrap_host_compiler, + rustup_toolchain_name, bootstrap_host_compiler.triple.clone(), ); diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 67c4cfa4417..d2e712941bf 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use std::process::{self, Command}; use super::path::{Dirs, RelPath}; -use super::rustc_info::{get_file_name, get_rustc_version, get_toolchain_name}; +use super::rustc_info::{get_file_name, get_rustc_version}; use super::utils::{remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler}; use super::SysrootKind; @@ -17,6 +17,7 @@ pub(crate) fn build_sysroot( sysroot_kind: SysrootKind, cg_clif_dylib_src: &Path, bootstrap_host_compiler: &Compiler, + rustup_toolchain_name: Option<&str>, target_triple: String, ) -> Compiler { eprintln!("[BUILD] sysroot {:?}", sysroot_kind); @@ -41,18 +42,29 @@ pub(crate) fn build_sysroot( // Build and copy rustc and cargo wrappers let wrapper_base_name = get_file_name(&bootstrap_host_compiler.rustc, "____", "bin"); - let toolchain_name = get_toolchain_name(); for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] { let wrapper_name = wrapper_base_name.replace("____", wrapper); let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc); let wrapper_path = DIST_DIR.to_path(dirs).join(&wrapper_name); build_cargo_wrapper_cmd - .env("TOOLCHAIN_NAME", toolchain_name.clone()) .arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs"))) .arg("-o") .arg(&wrapper_path) .arg("-Cstrip=debuginfo"); + if let Some(rustup_toolchain_name) = &rustup_toolchain_name { + build_cargo_wrapper_cmd + .env("TOOLCHAIN_NAME", rustup_toolchain_name) + .env_remove("CARGO") + .env_remove("RUSTC") + .env_remove("RUSTDOC"); + } else { + build_cargo_wrapper_cmd + .env_remove("TOOLCHAIN_NAME") + .env("CARGO", &bootstrap_host_compiler.cargo) + .env("RUSTC", &bootstrap_host_compiler.rustc) + .env("RUSTDOC", &bootstrap_host_compiler.rustdoc); + } spawn_and_wait(build_cargo_wrapper_cmd); try_hard_link(wrapper_path, BIN_DIR.to_path(dirs).join(wrapper_name)); } diff --git a/build_system/mod.rs b/build_system/mod.rs index 58b21f64d37..d1d6f34dcff 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -103,6 +103,14 @@ pub(crate) fn main() { } } + let rustup_toolchain_name = match (env::var("CARGO"), env::var("RUSTC"), env::var("RUSTDOC")) { + (Ok(_), Ok(_), Ok(_)) => None, + (Err(_), Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()), + _ => { + eprintln!("All of CARGO, RUSTC and RUSTDOC need to be set or none must be set"); + process::exit(1); + } + }; let bootstrap_host_compiler = { let cargo = rustc_info::get_cargo_path(); let rustc = rustc_info::get_rustc_path(); @@ -173,6 +181,7 @@ pub(crate) fn main() { sysroot_kind, &cg_clif_dylib, &bootstrap_host_compiler, + rustup_toolchain_name.as_deref(), target_triple.clone(), ); } @@ -181,7 +190,14 @@ pub(crate) fn main() { eprintln!("Abi-cafe doesn't support cross-compilation"); process::exit(1); } - abi_cafe::run(channel, sysroot_kind, &dirs, &cg_clif_dylib, &bootstrap_host_compiler); + abi_cafe::run( + channel, + sysroot_kind, + &dirs, + &cg_clif_dylib, + rustup_toolchain_name.as_deref(), + &bootstrap_host_compiler, + ); } Command::Build => { build_sysroot::build_sysroot( @@ -190,6 +206,7 @@ pub(crate) fn main() { sysroot_kind, &cg_clif_dylib, &bootstrap_host_compiler, + rustup_toolchain_name.as_deref(), target_triple, ); } @@ -200,6 +217,7 @@ pub(crate) fn main() { sysroot_kind, &cg_clif_dylib, &bootstrap_host_compiler, + rustup_toolchain_name.as_deref(), target_triple, ); bench::benchmark(&dirs, &bootstrap_host_compiler); diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 63f41ad5662..c14b4fdaf33 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -34,6 +34,9 @@ pub(crate) fn get_toolchain_name() -> String { } pub(crate) fn get_cargo_path() -> PathBuf { + if let Ok(cargo) = std::env::var("CARGO") { + return PathBuf::from(cargo); + } let cargo_path = Command::new("rustup") .stderr(Stdio::inherit()) .args(&["which", "cargo"]) @@ -44,6 +47,9 @@ pub(crate) fn get_cargo_path() -> PathBuf { } pub(crate) fn get_rustc_path() -> PathBuf { + if let Ok(rustc) = std::env::var("RUSTC") { + return PathBuf::from(rustc); + } let rustc_path = Command::new("rustup") .stderr(Stdio::inherit()) .args(&["which", "rustc"]) @@ -54,6 +60,9 @@ pub(crate) fn get_rustc_path() -> PathBuf { } pub(crate) fn get_rustdoc_path() -> PathBuf { + if let Ok(rustdoc) = std::env::var("RUSTDOC") { + return PathBuf::from(rustdoc); + } let rustc_path = Command::new("rustup") .stderr(Stdio::inherit()) .args(&["which", "rustdoc"]) diff --git a/build_system/tests.rs b/build_system/tests.rs index 3af74e1e97c..40bcf1e0c1e 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -217,6 +217,7 @@ pub(crate) fn run_tests( sysroot_kind: SysrootKind, cg_clif_dylib: &Path, bootstrap_host_compiler: &Compiler, + rustup_toolchain_name: Option<&str>, target_triple: String, ) { if config::get_bool("testsuite.no_sysroot") { @@ -226,6 +227,7 @@ pub(crate) fn run_tests( SysrootKind::None, cg_clif_dylib, bootstrap_host_compiler, + rustup_toolchain_name, target_triple.clone(), ); @@ -251,6 +253,7 @@ pub(crate) fn run_tests( sysroot_kind, cg_clif_dylib, bootstrap_host_compiler, + rustup_toolchain_name, target_triple.clone(), ); // Rust's build system denies a couple of lints that trigger on several of the test diff --git a/build_system/usage.txt b/build_system/usage.txt index e7b4f0af2d9..1aee083f8df 100644 --- a/build_system/usage.txt +++ b/build_system/usage.txt @@ -30,8 +30,9 @@ OPTIONS: Require Cargo.lock and cache are up to date REQUIREMENTS: - * Rustup: The build system has a hard coded dependency on rustup to install the right nightly - version and make sure it is used where necessary. + * Rustup: By default rustup is used to install the right nightly version. If you don't want to + use rustup, you can manually install the nightly version indicated by rust-toolchain.toml and + point the CARGO, RUSTC and RUSTDOC env vars to the right executables. * Git: `./y.rs prepare` uses git for applying patches and on Windows for downloading test repos. * Curl and tar (non-Windows only): Used by `./y.rs prepare` to download a single commit for repos. Git will be used to clone the whole repo when using Windows. diff --git a/scripts/cargo-clif.rs b/scripts/cargo-clif.rs index e2db7d03a9d..0d5d9f7db01 100644 --- a/scripts/cargo-clif.rs +++ b/scripts/cargo-clif.rs @@ -28,8 +28,13 @@ fn main() { env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags); env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags); - // Ensure that the right toolchain is used - env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); + let cargo = if let Some(cargo) = option_env!("CARGO") { + cargo + } else { + // Ensure that the right toolchain is used + env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME")); + "cargo" + }; let args: Vec<_> = match env::args().nth(1).as_deref() { Some("jit") => { @@ -64,10 +69,10 @@ fn main() { }; #[cfg(unix)] - panic!("Failed to spawn cargo: {}", Command::new("cargo").args(args).exec()); + panic!("Failed to spawn cargo: {}", Command::new(cargo).args(args).exec()); #[cfg(not(unix))] std::process::exit( - Command::new("cargo").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1), + Command::new(cargo).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1), ); } diff --git a/scripts/rustc-clif.rs b/scripts/rustc-clif.rs index 7ef3488672d..df94b80b34f 100644 --- a/scripts/rustc-clif.rs +++ b/scripts/rustc-clif.rs @@ -30,14 +30,19 @@ fn main() { } args.extend(passed_args); - // Ensure that the right toolchain is used - env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); + let rustc = if let Some(rustc) = option_env!("RUSTC") { + rustc + } else { + // Ensure that the right toolchain is used + env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME")); + "rustc" + }; #[cfg(unix)] - panic!("Failed to spawn rustc: {}", Command::new("rustc").args(args).exec()); + panic!("Failed to spawn rustc: {}", Command::new(rustc).args(args).exec()); #[cfg(not(unix))] std::process::exit( - Command::new("rustc").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1), + Command::new(rustc).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1), ); } diff --git a/scripts/rustdoc-clif.rs b/scripts/rustdoc-clif.rs index 72024e0d494..36a00dc676e 100644 --- a/scripts/rustdoc-clif.rs +++ b/scripts/rustdoc-clif.rs @@ -30,14 +30,19 @@ fn main() { } args.extend(passed_args); - // Ensure that the right toolchain is used - env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); + let rustdoc = if let Some(rustdoc) = option_env!("RUSTDOC") { + rustdoc + } else { + // Ensure that the right toolchain is used + env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME")); + "rustdoc" + }; #[cfg(unix)] - panic!("Failed to spawn rustdoc: {}", Command::new("rustdoc").args(args).exec()); + panic!("Failed to spawn rustdoc: {}", Command::new(rustdoc).args(args).exec()); #[cfg(not(unix))] std::process::exit( - Command::new("rustdoc").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1), + Command::new(rustdoc).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1), ); } From a555b8ab7ec6d4f26233ab2b313ddb4ddbcc3457 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 16 Feb 2023 15:11:45 +0000 Subject: [PATCH 33/89] Add fixme --- build_system/rustc_info.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index c14b4fdaf33..42cec0c6935 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -82,6 +82,7 @@ pub(crate) fn get_default_sysroot(rustc: &Path) -> PathBuf { Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned() } +// FIXME call once for each target and pass result around in struct pub(crate) fn get_file_name(rustc: &Path, crate_name: &str, crate_type: &str) -> String { let file_name = Command::new(rustc) .stderr(Stdio::inherit()) From 24f1569c85e3f6958aaa9d36b3684bcd2da2a262 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 22 May 2023 18:35:56 +0000 Subject: [PATCH 34/89] Enable overflow-checks on CI Unlike rustc with cargo debug-assertions = true doesn't imply overflow-checks = true --- build_system/build_backend.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 4b740fa2db6..d9db1d109c2 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -28,6 +28,7 @@ pub(crate) fn build_backend( if !is_ci_opt() { cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true"); + cmd.env("CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS", "true"); } } From 031bfa659ff00583ce9195fd72cdbedbefce7d91 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 23 May 2023 11:48:34 +0000 Subject: [PATCH 35/89] Print symbol name in PrintOnPanic for define_function --- src/base.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/base.rs b/src/base.rs index e9dbea1be67..f5de5166776 100644 --- a/src/base.rs +++ b/src/base.rs @@ -156,6 +156,7 @@ pub(crate) fn compile_fn( write!(clif, " {}", isa_flag).unwrap(); } writeln!(clif, "\n").unwrap(); + writeln!(clif, "; symbol {}", codegened_func.symbol_name).unwrap(); crate::PrintOnPanic(move || { let mut clif = clif.clone(); ::cranelift_codegen::write::decorate_function( From c87dfd9c9d0ccd4bc7465744039a7f222ba8e614 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 23 May 2023 11:55:03 +0000 Subject: [PATCH 36/89] Update Cranelift to 0.96.1 There was a minor bug in Wasmtime that needed a new release. Nothing changed in Cranelift. --- Cargo.lock | 52 ++++++++++++++++++++++++++-------------------------- Cargo.toml | 12 ++++++------ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee987207532..3e411ff2887 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,18 +51,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfa12cfd843d39182f3e466b3b1a2b53ff348b34eb3579fcd4ee818d177a9" +checksum = "9b6160c0a96253993b79fb7e0983534a4515ecf666120ddf8f92068114997ebc" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3efdd75f82d338ebce8f6e492fac7205e4b1091bb76da74ad27894b224052c5" +checksum = "7b38da5f63562e42f3c929d7c76871098e5ad12c8ab44b0659ffc529f22a5b3a" dependencies = [ "bumpalo", "cranelift-bforest", @@ -81,39 +81,39 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e03ccd2e7959cb8c1434aeda5a80599a65f71ba75e00bf969d5f8e2dc7ca11d3" +checksum = "011371e213e163b55dd9e8404b3f2d9fa52cd14dc2f3dc5b83e61ffceff126db" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e64284ccb56442849500cf17a8cc3681a254ec1bb8f0c887f55b2f81beab70" +checksum = "1bf97dde7f5ad571161cdd203a2c9c88682ef669830aea3c14ea5d164ef8bb43" [[package]] name = "cranelift-control" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "537278bd7c9389b6d820d0b8f549460445d8e1cb1d21b617ac2e44aaf2f686cf" +checksum = "fd9a9254aee733b0f2b68e5eaaf0337ad53cb23252a056c10a35370551be8d40" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e234fff84b1941dd25fa3e24c466283256b377997ccbd85f592066389251796" +checksum = "baf39a33ee39479d1337cd9333f3c09786c5a0ca1ec509edcaf9d1346d5de0e5" [[package]] name = "cranelift-frontend" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ebfb3cc39ef246aecc9bbd44f6259501cf243da19d45888409cb7f06a34bd0" +checksum = "65e260b92a193a0a2dccc3938f133d9532e7dcfe8d03e36bf8b7d3518c1c1793" dependencies = [ "cranelift-codegen", "log", @@ -123,15 +123,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f22fdc6c4ce755b44f92f2e3e1f7f1138f9ee5c3d99e2e2b20418475713a2c6c" +checksum = "9446c8e1aadfcdacee1a49592bc2c25d1d9bf5484782c163e7f5485c92cd3c1c" [[package]] name = "cranelift-jit" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65b7970f8950043cada68dcb8b1e9ea5f00d9b7aaf8cb139b4954fd4fb365bc2" +checksum = "689a6df165d0f860c1e1a3d53c28944e2743c3e9ee4c678cf190fe60ad7a6ef5" dependencies = [ "anyhow", "cranelift-codegen", @@ -149,9 +149,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1413dae1da005e5f54b185b0173f13b4184cd4d80ec3cc8c37ee5666c20a9ccb" +checksum = "0b1402d6ff1695b429536b2eaa126db560fc94c375ed0e9cfb15051fc07427f7" dependencies = [ "anyhow", "cranelift-codegen", @@ -160,9 +160,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e961c2eba1af0ec7422170fc1ba635d06000f466ee4d4811f3d4cd6f4594327f" +checksum = "eac916f3c5aff4b817e42fc2e682292b931495b3fe2603d5e3c3cf602d74e344" dependencies = [ "cranelift-codegen", "libc", @@ -171,9 +171,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.96.0" +version = "0.96.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1521f1e47b81d913f032e8ab246c2c8201c6da9fd7dcef6afee07d2afa31811" +checksum = "23860f4cd064017f2108e6bc5d25660a77cd6eea77f1ac0756870a00abb12e93" dependencies = [ "anyhow", "cranelift-codegen", @@ -374,9 +374,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasmtime-jit-icache-coherence" -version = "9.0.0" +version = "9.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc60ec61519028279b9e8b6119a52c23b7ce2f2a8f0ec3cbe12aeb6ee9b2c549" +checksum = "7d90933b781e1cef7656baed671c7a90bdba0c1c694e04fdd4124419308f5cbb" dependencies = [ "cfg-if", "libc", diff --git a/Cargo.toml b/Cargo.toml index 141d7cb8e1c..145b1150423 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,12 +15,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.96", features = ["unwind", "all-arch"] } -cranelift-frontend = { version = "0.96" } -cranelift-module = { version = "0.96" } -cranelift-native = { version = "0.96" } -cranelift-jit = { version = "0.96", optional = true } -cranelift-object = { version = "0.96" } +cranelift-codegen = { version = "0.96.1", features = ["unwind", "all-arch"] } +cranelift-frontend = { version = "0.96.1" } +cranelift-module = { version = "0.96.1" } +cranelift-native = { version = "0.96.1" } +cranelift-jit = { version = "0.96.1", optional = true } +cranelift-object = { version = "0.96.1" } target-lexicon = "0.12.0" gimli = { version = "0.27.2", default-features = false, features = ["write"]} object = { version = "0.30.3", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From a3b816be53b5d3eae48e7291836442f6dff9e318 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 24 May 2023 14:33:43 +0000 Subject: [PATCH 37/89] Use `is_some_and`/`is_ok_and` in less obvious spots --- src/abi/mod.rs | 10 ++++------ src/base.rs | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 73a3e3353f3..84e09cf0abe 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -432,11 +432,9 @@ pub(crate) fn codegen_terminator_call<'tcx>( let is_cold = if fn_sig.abi() == Abi::RustCold { true } else { - instance - .map(|inst| { - fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD) - }) - .unwrap_or(false) + instance.is_some_and(|inst| { + fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD) + }) }; if is_cold { fx.bcx.set_cold_block(fx.bcx.current_block().unwrap()); @@ -470,7 +468,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( }; // Pass the caller location for `#[track_caller]`. - if instance.map(|inst| inst.def.requires_caller_location(fx.tcx)).unwrap_or(false) { + if instance.is_some_and(|inst| inst.def.requires_caller_location(fx.tcx)) { let caller_location = fx.get_caller_location(source_info); args.push(CallArgument { value: caller_location, is_owned: false }); } diff --git a/src/base.rs b/src/base.rs index 25fd5ca3ae8..9c6a0fae327 100644 --- a/src/base.rs +++ b/src/base.rs @@ -630,11 +630,11 @@ fn codegen_stmt<'tcx>( let to_ty = fx.monomorphize(to_ty); fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { - ty.builtin_deref(true) - .map(|ty::TypeAndMut { ty: pointee_ty, mutbl: _ }| { + ty.builtin_deref(true).is_some_and( + |ty::TypeAndMut { ty: pointee_ty, mutbl: _ }| { has_ptr_meta(fx.tcx, pointee_ty) - }) - .unwrap_or(false) + }, + ) } if is_fat_ptr(fx, from_ty) { From 5b3bc29008643203b4de3ffb4c5b5141039c88e6 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 15 Feb 2023 19:32:58 +0000 Subject: [PATCH 38/89] Allow testing a cranelift backend built into rustc itself This avoids building cranelift twice in rust's CI and is a lot easier than trying to make building of codegen backends work from within a cargo invocation done by rust's build system. --- build_system/abi_cafe.rs | 15 +++++++---- build_system/build_sysroot.rs | 50 +++++++++++++++++++++++------------ build_system/mod.rs | 29 +++++++++++++++----- build_system/tests.rs | 5 ++-- build_system/usage.txt | 4 +++ scripts/cargo-clif.rs | 26 ++++++++++-------- scripts/rustc-clif.rs | 10 ++++--- scripts/rustdoc-clif.rs | 10 ++++--- 8 files changed, 101 insertions(+), 48 deletions(-) diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index 8ffd4852083..9634430d116 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -1,10 +1,8 @@ -use std::path::Path; - use super::build_sysroot; use super::path::Dirs; use super::prepare::GitRepo; use super::utils::{spawn_and_wait, CargoProject, Compiler}; -use super::SysrootKind; +use super::{CodegenBackend, SysrootKind}; static ABI_CAFE_REPO: GitRepo = GitRepo::github("Gankra", "abi-cafe", "4c6dc8c9c687e2b3a760ff2176ce236872b37212", "abi-cafe"); @@ -15,7 +13,7 @@ pub(crate) fn run( channel: &str, sysroot_kind: SysrootKind, dirs: &Dirs, - cg_clif_dylib: &Path, + cg_clif_dylib: &CodegenBackend, rustup_toolchain_name: Option<&str>, bootstrap_host_compiler: &Compiler, ) { @@ -41,7 +39,14 @@ pub(crate) fn run( cmd.arg("--pairs"); cmd.args(pairs); cmd.arg("--add-rustc-codegen-backend"); - cmd.arg(format!("cgclif:{}", cg_clif_dylib.display())); + match cg_clif_dylib { + CodegenBackend::Local(path) => { + cmd.arg(format!("cgclif:{}", path.display())); + } + CodegenBackend::Builtin(name) => { + cmd.arg(format!("cgclif:{name}")); + } + } cmd.current_dir(ABI_CAFE.source_dir(dirs)); spawn_and_wait(cmd); diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index d2e712941bf..dab9c77d1a4 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -5,7 +5,7 @@ use std::process::{self, Command}; use super::path::{Dirs, RelPath}; use super::rustc_info::{get_file_name, get_rustc_version}; use super::utils::{remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler}; -use super::SysrootKind; +use super::{CodegenBackend, SysrootKind}; static DIST_DIR: RelPath = RelPath::DIST; static BIN_DIR: RelPath = RelPath::DIST.join("bin"); @@ -15,7 +15,7 @@ pub(crate) fn build_sysroot( dirs: &Dirs, channel: &str, sysroot_kind: SysrootKind, - cg_clif_dylib_src: &Path, + cg_clif_dylib_src: &CodegenBackend, bootstrap_host_compiler: &Compiler, rustup_toolchain_name: Option<&str>, target_triple: String, @@ -28,17 +28,23 @@ pub(crate) fn build_sysroot( let is_native = bootstrap_host_compiler.triple == target_triple; - // Copy the backend - let cg_clif_dylib_path = if cfg!(windows) { - // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the - // binaries. - BIN_DIR - } else { - LIB_DIR - } - .to_path(dirs) - .join(cg_clif_dylib_src.file_name().unwrap()); - try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path); + let cg_clif_dylib_path = match cg_clif_dylib_src { + CodegenBackend::Local(src_path) => { + // Copy the backend + let cg_clif_dylib_path = if cfg!(windows) { + // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the + // binaries. + BIN_DIR + } else { + LIB_DIR + } + .to_path(dirs) + .join(src_path.file_name().unwrap()); + try_hard_link(src_path, &cg_clif_dylib_path); + CodegenBackend::Local(cg_clif_dylib_path) + } + CodegenBackend::Builtin(name) => CodegenBackend::Builtin(name.clone()), + }; // Build and copy rustc and cargo wrappers let wrapper_base_name = get_file_name(&bootstrap_host_compiler.rustc, "____", "bin"); @@ -65,6 +71,9 @@ pub(crate) fn build_sysroot( .env("RUSTC", &bootstrap_host_compiler.rustc) .env("RUSTDOC", &bootstrap_host_compiler.rustdoc); } + if let CodegenBackend::Builtin(name) = cg_clif_dylib_src { + build_cargo_wrapper_cmd.env("BUILTIN_BACKEND", name); + } spawn_and_wait(build_cargo_wrapper_cmd); try_hard_link(wrapper_path, BIN_DIR.to_path(dirs).join(wrapper_name)); } @@ -159,7 +168,7 @@ fn build_sysroot_for_triple( dirs: &Dirs, channel: &str, compiler: Compiler, - cg_clif_dylib_path: &Path, + cg_clif_dylib_path: &CodegenBackend, sysroot_kind: SysrootKind, ) -> SysrootTarget { match sysroot_kind { @@ -167,7 +176,7 @@ fn build_sysroot_for_triple( .unwrap_or(SysrootTarget { triple: compiler.triple, libs: vec![] }), SysrootKind::Llvm => build_llvm_sysroot_for_triple(compiler), SysrootKind::Clif => { - build_clif_sysroot_for_triple(dirs, channel, compiler, &cg_clif_dylib_path) + build_clif_sysroot_for_triple(dirs, channel, compiler, cg_clif_dylib_path) } } } @@ -211,7 +220,7 @@ fn build_clif_sysroot_for_triple( dirs: &Dirs, channel: &str, mut compiler: Compiler, - cg_clif_dylib_path: &Path, + cg_clif_dylib_path: &CodegenBackend, ) -> SysrootTarget { match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) { Err(e) => { @@ -249,7 +258,14 @@ fn build_clif_sysroot_for_triple( // Build sysroot let mut rustflags = " -Zforce-unstable-if-unmarked -Cpanic=abort".to_string(); - rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap())); + match cg_clif_dylib_path { + CodegenBackend::Local(path) => { + rustflags.push_str(&format!(" -Zcodegen-backend={}", path.to_str().unwrap())); + } + CodegenBackend::Builtin(name) => { + rustflags.push_str(&format!(" -Zcodegen-backend={name}")); + } + }; // Necessary for MinGW to find rsbegin.o and rsend.o rustflags .push_str(&format!(" --sysroot {}", RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap())); diff --git a/build_system/mod.rs b/build_system/mod.rs index d1d6f34dcff..2ca5316408e 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -43,6 +43,12 @@ pub(crate) enum SysrootKind { Llvm, } +#[derive(Clone, Debug)] +pub(crate) enum CodegenBackend { + Local(PathBuf), + Builtin(String), +} + pub(crate) fn main() { if env::var("RUST_BACKTRACE").is_err() { env::set_var("RUST_BACKTRACE", "1"); @@ -79,6 +85,7 @@ pub(crate) fn main() { let mut sysroot_kind = SysrootKind::Clif; let mut use_unstable_features = true; let mut frozen = false; + let mut use_backend = None; while let Some(arg) = args.next().as_deref() { match arg { "--out-dir" => { @@ -98,6 +105,12 @@ pub(crate) fn main() { } "--no-unstable-features" => use_unstable_features = false, "--frozen" => frozen = true, + "--use-backend" => { + use_backend = Some(match args.next() { + Some(name) => name, + None => arg_error!("--use-backend requires argument"), + }); + } flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag), arg => arg_error!("Unexpected argument {}", arg), } @@ -164,12 +177,16 @@ pub(crate) fn main() { env::set_var("RUSTC", "rustc_should_be_set_explicitly"); env::set_var("RUSTDOC", "rustdoc_should_be_set_explicitly"); - let cg_clif_dylib = build_backend::build_backend( - &dirs, - channel, - &bootstrap_host_compiler, - use_unstable_features, - ); + let cg_clif_dylib = if let Some(name) = use_backend { + CodegenBackend::Builtin(name) + } else { + CodegenBackend::Local(build_backend::build_backend( + &dirs, + channel, + &bootstrap_host_compiler, + use_unstable_features, + )) + }; match command { Command::Prepare => { // Handled above diff --git a/build_system/tests.rs b/build_system/tests.rs index 40bcf1e0c1e..13bf9c70c3e 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -3,11 +3,10 @@ use super::config; use super::path::{Dirs, RelPath}; use super::prepare::GitRepo; use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler}; -use super::SysrootKind; +use super::{CodegenBackend, SysrootKind}; use std::env; use std::ffi::OsStr; use std::fs; -use std::path::Path; use std::process::Command; static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::BUILD.join("example"); @@ -215,7 +214,7 @@ pub(crate) fn run_tests( dirs: &Dirs, channel: &str, sysroot_kind: SysrootKind, - cg_clif_dylib: &Path, + cg_clif_dylib: &CodegenBackend, bootstrap_host_compiler: &Compiler, rustup_toolchain_name: Option<&str>, target_triple: String, diff --git a/build_system/usage.txt b/build_system/usage.txt index 1aee083f8df..3bc18a93331 100644 --- a/build_system/usage.txt +++ b/build_system/usage.txt @@ -29,6 +29,10 @@ OPTIONS: --frozen Require Cargo.lock and cache are up to date + --use-backend NAME + Use the existing Cranelift (or other) backend of the rustc with which we built. + Warning: This is meant for use in rust's CI only! + REQUIREMENTS: * Rustup: By default rustup is used to install the right nightly version. If you don't want to use rustup, you can manually install the nightly version indicated by rust-toolchain.toml and diff --git a/scripts/cargo-clif.rs b/scripts/cargo-clif.rs index 0d5d9f7db01..99b97be24e6 100644 --- a/scripts/cargo-clif.rs +++ b/scripts/cargo-clif.rs @@ -12,17 +12,21 @@ fn main() { let mut rustflags = String::new(); rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend="); - rustflags.push_str( - sysroot - .join(if cfg!(windows) { "bin" } else { "lib" }) - .join( - env::consts::DLL_PREFIX.to_string() - + "rustc_codegen_cranelift" - + env::consts::DLL_SUFFIX, - ) - .to_str() - .unwrap(), - ); + if let Some(name) = option_env!("BUILTIN_BACKEND") { + rustflags.push_str(name); + } else { + rustflags.push_str( + sysroot + .join(if cfg!(windows) { "bin" } else { "lib" }) + .join( + env::consts::DLL_PREFIX.to_string() + + "rustc_codegen_cranelift" + + env::consts::DLL_SUFFIX, + ) + .to_str() + .unwrap(), + ); + } rustflags.push_str(" --sysroot "); rustflags.push_str(sysroot.to_str().unwrap()); env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags); diff --git a/scripts/rustc-clif.rs b/scripts/rustc-clif.rs index df94b80b34f..33d51bdddea 100644 --- a/scripts/rustc-clif.rs +++ b/scripts/rustc-clif.rs @@ -19,9 +19,13 @@ fn main() { let mut args = vec![]; args.push(OsString::from("-Cpanic=abort")); args.push(OsString::from("-Zpanic-abort-tests")); - let mut codegen_backend_arg = OsString::from("-Zcodegen-backend="); - codegen_backend_arg.push(cg_clif_dylib_path); - args.push(codegen_backend_arg); + if let Some(name) = option_env!("BUILTIN_BACKEND") { + args.push(OsString::from(format!("-Zcodegen-backend={name}"))) + } else { + let mut codegen_backend_arg = OsString::from("-Zcodegen-backend="); + codegen_backend_arg.push(cg_clif_dylib_path); + args.push(codegen_backend_arg); + } if !passed_args.iter().any(|arg| { arg == "--sysroot" || arg.to_str().map(|s| s.starts_with("--sysroot=")) == Some(true) }) { diff --git a/scripts/rustdoc-clif.rs b/scripts/rustdoc-clif.rs index 36a00dc676e..10582cc7bb3 100644 --- a/scripts/rustdoc-clif.rs +++ b/scripts/rustdoc-clif.rs @@ -19,9 +19,13 @@ fn main() { let mut args = vec![]; args.push(OsString::from("-Cpanic=abort")); args.push(OsString::from("-Zpanic-abort-tests")); - let mut codegen_backend_arg = OsString::from("-Zcodegen-backend="); - codegen_backend_arg.push(cg_clif_dylib_path); - args.push(codegen_backend_arg); + if let Some(name) = option_env!("BUILTIN_BACKEND") { + args.push(OsString::from(format!("-Zcodegen-backend={name}"))) + } else { + let mut codegen_backend_arg = OsString::from("-Zcodegen-backend="); + codegen_backend_arg.push(cg_clif_dylib_path); + args.push(codegen_backend_arg); + } if !passed_args.iter().any(|arg| { arg == "--sysroot" || arg.to_str().map(|s| s.starts_with("--sysroot=")) == Some(true) }) { From 72e67c862f9d81a54850d78804ee0de6d0e413a8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 24 May 2023 17:26:29 +0000 Subject: [PATCH 39/89] Fix compiling all tests with LLVM --- example/mini_core.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index ea97e9f060e..d9ce2d6dfa7 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -526,7 +526,7 @@ impl CoerceUnsized> for Unique where T: Unsiz impl DispatchFromDyn> for Unique where T: Unsize {} #[lang = "owned_box"] -pub struct Box(Unique, ()); +pub struct Box(Unique, A); impl, U: ?Sized> CoerceUnsized> for Box {} @@ -541,7 +541,7 @@ impl Box { } } -impl Drop for Box { +impl Drop for Box { fn drop(&mut self) { // drop is currently performed by compiler. } From 134dc334857e453c50f8ea31b13cbda106204f20 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:01:32 +0000 Subject: [PATCH 40/89] Fix testing with unstable features disabled --- build_system/mod.rs | 1 + build_system/tests.rs | 34 +++++++++++++++++++++++++++----- example/mini_core_hello_world.rs | 18 +++++++++++++---- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/build_system/mod.rs b/build_system/mod.rs index 2ca5316408e..0110011169d 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -196,6 +196,7 @@ pub(crate) fn main() { &dirs, channel, sysroot_kind, + use_unstable_features, &cg_clif_dylib, &bootstrap_host_compiler, rustup_toolchain_name.as_deref(), diff --git a/build_system/tests.rs b/build_system/tests.rs index 13bf9c70c3e..7efb960697e 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -214,6 +214,7 @@ pub(crate) fn run_tests( dirs: &Dirs, channel: &str, sysroot_kind: SysrootKind, + use_unstable_features: bool, cg_clif_dylib: &CodegenBackend, bootstrap_host_compiler: &Compiler, rustup_toolchain_name: Option<&str>, @@ -233,6 +234,7 @@ pub(crate) fn run_tests( let runner = TestRunner::new( dirs.clone(), target_compiler, + use_unstable_features, bootstrap_host_compiler.triple == target_triple, ); @@ -262,6 +264,7 @@ pub(crate) fn run_tests( let runner = TestRunner::new( dirs.clone(), target_compiler, + use_unstable_features, bootstrap_host_compiler.triple == target_triple, ); @@ -282,12 +285,18 @@ pub(crate) fn run_tests( struct TestRunner { is_native: bool, jit_supported: bool, + use_unstable_features: bool, dirs: Dirs, target_compiler: Compiler, } impl TestRunner { - fn new(dirs: Dirs, mut target_compiler: Compiler, is_native: bool) -> Self { + fn new( + dirs: Dirs, + mut target_compiler: Compiler, + use_unstable_features: bool, + is_native: bool, + ) -> Self { if let Ok(rustflags) = env::var("RUSTFLAGS") { target_compiler.rustflags.push(' '); target_compiler.rustflags.push_str(&rustflags); @@ -302,11 +311,12 @@ impl TestRunner { target_compiler.rustflags.push_str(" -Clink-arg=-undefined -Clink-arg=dynamic_lookup"); } - let jit_supported = is_native + let jit_supported = use_unstable_features + && is_native && target_compiler.triple.contains("x86_64") && !target_compiler.triple.contains("windows"); - Self { is_native, jit_supported, dirs, target_compiler } + Self { is_native, jit_supported, use_unstable_features, dirs, target_compiler } } fn run_testsuite(&self, tests: &[TestCase]) { @@ -325,10 +335,24 @@ impl TestRunner { match *cmd { TestCaseCmd::Custom { func } => func(self), TestCaseCmd::BuildLib { source, crate_types } => { - self.run_rustc([source, "--crate-type", crate_types]); + if self.use_unstable_features { + self.run_rustc([source, "--crate-type", crate_types]); + } else { + self.run_rustc([ + source, + "--crate-type", + crate_types, + "--cfg", + "no_unstable_features", + ]); + } } TestCaseCmd::BuildBinAndRun { source, args } => { - self.run_rustc([source]); + if self.use_unstable_features { + self.run_rustc([source]); + } else { + self.run_rustc([source, "--cfg", "no_unstable_features"]); + } self.run_out_command( source.split('/').last().unwrap().split('.').next().unwrap(), args, diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 3232cd503fc..e3452520e7b 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -322,7 +322,12 @@ fn main() { #[cfg(all(not(jit), not(all(windows, target_env = "gnu"))))] test_tls(); - #[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))] + #[cfg(all( + not(jit), + not(no_unstable_features), + target_arch = "x86_64", + any(target_os = "linux", target_os = "darwin") + ))] unsafe { global_asm_test(); } @@ -350,12 +355,17 @@ fn main() { let _a = f.0[0]; } -#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))] +#[cfg(all( + not(jit), + not(no_unstable_features), + target_arch = "x86_64", + any(target_os = "linux", target_os = "darwin") +))] extern "C" { fn global_asm_test(); } -#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))] +#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "linux"))] global_asm! { " .global global_asm_test @@ -365,7 +375,7 @@ global_asm! { " } -#[cfg(all(not(jit), target_arch = "x86_64", target_os = "darwin"))] +#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "darwin"))] global_asm! { " .global _global_asm_test From f9dabd8b883bc6deed043ff01180f8c728fdb829 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 24 May 2023 20:26:24 +0000 Subject: [PATCH 41/89] Remove ExpnKind::Inlined. --- src/common.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/common.rs b/src/common.rs index ccb3a0c4f27..5eaa988dd09 100644 --- a/src/common.rs +++ b/src/common.rs @@ -413,11 +413,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { // Note: must be kept in sync with get_caller_location from cg_ssa pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> { - let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, mut span: Span| { - // Remove `Inlined` marks as they pollute `expansion_cause`. - while span.is_inlined() { - span.remove_mark(); - } + let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| { let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo()); let const_loc = fx.tcx.const_caller_location(( From 03f275bc5ae941e314aa0790d8324443242055e7 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 25 May 2023 17:30:23 +0000 Subject: [PATCH 42/89] Remove DesugaringKind::Replace. --- src/base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index 9c6a0fae327..fcfa0b862d4 100644 --- a/src/base.rs +++ b/src/base.rs @@ -473,7 +473,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { | TerminatorKind::GeneratorDrop => { bug!("shouldn't exist at codegen {:?}", bb_data.terminator()); } - TerminatorKind::Drop { place, target, unwind: _ } => { + TerminatorKind::Drop { place, target, unwind: _, replace: _ } => { let drop_place = codegen_place(fx, *place); crate::abi::codegen_drop(fx, source_info, drop_place); From 8aa3eba564275448a7f443646fefbe6558a6e34c Mon Sep 17 00:00:00 2001 From: AngelicosPhosphoros Date: Sun, 21 May 2023 21:53:02 +0400 Subject: [PATCH 43/89] Added build instructions for cranelift backend as part of Rust repo All other instructions assume that user works with separate repository than Rust compiler repository. When one follows default instructions, cranelift codegen tries to use different sys-root and compiler internal crates which leads to compiler errors when building it. I needed to do all this steps while adding new intrinsic to rustc. --- Readme.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Readme.md b/Readme.md index c5222982aa7..26dccf309e1 100644 --- a/Readme.md +++ b/Readme.md @@ -42,6 +42,32 @@ This will build your project with rustc_codegen_cranelift instead of the usual L For additional ways to use rustc_codegen_cranelift like the JIT mode see [usage.md](docs/usage.md). +## Building and testing with changes in rustc code + +This is useful when changing code in `rustc_codegen_cranelift` as part of changing [main Rust repository](https://github.com/rust-lang/rust/). +This can happen, for example, when you are implementing a new compiler intrinsic. + +Instruction below uses `$RustCheckoutDir` as substitute for any folder where you cloned Rust repository. + +You need to do this steps to successfully compile and use the cranelift backend with your changes in rustc code: + +1. `cd $RustCheckoutDir` +2. Run `python x.py setup` and choose option for compiler (`b`). +3. Build compiler and necessary tools: `python x.py build --stage=2 compiler library/std src/tools/rustdoc src/tools/rustfmt` + * (Optional) You can also build cargo by adding `src/tools/cargo` to previous command. +4. Copy exectutable files from `./build/host/stage2-tools//release` +to `./build/host/stage2/bin/`. Note that you would need to do this every time you rebuilt `rust` repository. +5. Copy cargo from another toolchain: `cp $(rustup which cargo) .build//stage2/bin/cargo` + * Another option is to build it at step 3 and copy with other executables at step 4. +6. Link your new `rustc` to toolchain: `rustup toolchain link stage2 ./build/host/stage2/`. +7. (Windows only) compile y.rs: `rustc +stage2 -O y.rs`. +8. You need to prefix every `./y.rs` (or `y` if you built `y.rs`) command by `rustup run stage2` to make cg_clif use your local changes in rustc. + + * `rustup run stage2 ./y.rs prepare` + * `rustup run stage2 ./y.rs build` + * (Optional) run tests: `rustup run stage2 ./y.rs test` +9. Now you can use your cg_clif build to compile other Rust programs, e.g. you can open any Rust crate and run commands like `$RustCheckoutDir/compiler/rustc_codegen_cranelift/dist/cargo-clif build --release`. + ## Configuration See the documentation on the `BackendConfig` struct in [config.rs](src/config.rs) for all From b3415291a606e994dea56f6ea68d53b847ce1f29 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 26 May 2023 08:27:47 +0000 Subject: [PATCH 44/89] Rustup to rustc 1.71.0-nightly (a2b1646c5 2023-05-25) --- build_sysroot/Cargo.lock | 4 ++-- example/mini_core.rs | 3 +++ rust-toolchain | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index ad5381c88c9..a41c783ed00 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -50,9 +50,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.91" +version = "0.1.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571298a3cce7e2afbd3d61abb91a18667d5ab25993ec577a88ee8ac45f00cc3a" +checksum = "64518f1ae689f74db058bbfb3238dfe6eb53f59f4ae712f1ff4348628522e190" dependencies = [ "rustc-std-workspace-core", ] diff --git a/example/mini_core.rs b/example/mini_core.rs index d9ce2d6dfa7..772dd98fade 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -502,6 +502,9 @@ pub unsafe fn drop_in_place(to_drop: *mut T) { drop_in_place(to_drop); } +#[lang = "unpin"] +pub auto trait Unpin {} + #[lang = "deref"] pub trait Deref { type Target: ?Sized; diff --git a/rust-toolchain b/rust-toolchain index 83edc30874b..b8f06e0b4b1 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-05-12" +channel = "nightly-2023-05-26" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 202b14c80226e8bb48abad548b2924afefd1f979 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 26 May 2023 08:40:39 +0000 Subject: [PATCH 45/89] Fix rustc test suite --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index cb2211c7b1e..db304332a9d 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -138,6 +138,7 @@ rm -r tests/run-make/issue-30063 # same rm -r tests/run-make/multiple-emits # same rm -r tests/run-make/output-type-permutations # same rm -r tests/run-make/used # same +rm -r tests/run-make/no-alloc-shim # bugs in the test suite # ====================== From 72b194cd50696d01b2ee510973530b8246776b9a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 26 May 2023 08:44:25 +0000 Subject: [PATCH 46/89] Fix #[cfg(target_os)] for macOS Fixes #1376 --- example/mini_core_hello_world.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index e3452520e7b..5937866dea1 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -326,7 +326,7 @@ fn main() { not(jit), not(no_unstable_features), target_arch = "x86_64", - any(target_os = "linux", target_os = "darwin") + any(target_os = "linux", target_os = "macos") ))] unsafe { global_asm_test(); @@ -359,7 +359,7 @@ fn main() { not(jit), not(no_unstable_features), target_arch = "x86_64", - any(target_os = "linux", target_os = "darwin") + any(target_os = "linux", target_os = "macos") ))] extern "C" { fn global_asm_test(); @@ -375,7 +375,7 @@ global_asm! { " } -#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "darwin"))] +#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "macos"))] global_asm! { " .global _global_asm_test From bd45794be5138cfdc016a96978ae1248410e6b26 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 26 May 2023 11:11:21 +0000 Subject: [PATCH 47/89] Run tests against cg_llvm too in CI Fixes #1115 --- .github/workflows/main.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e4af73ea644..ed562d6ebe4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -108,6 +108,30 @@ jobs: run: ./y.rs test + # This job doesn't use cg_clif in any way. It checks that all cg_clif tests work with cg_llvm too. + test_llvm: + runs-on: ubuntu-latest + timeout-minutes: 60 + + defaults: + run: + shell: bash + + steps: + - uses: actions/checkout@v3 + + - name: Prepare dependencies + run: ./y.rs prepare + + - name: Disable JIT tests + run: | + sed -i 's/jit./#jit./' config.txt + + - name: Test + env: + TARGET_TRIPLE: x86_64-unknown-linux-gnu + run: ./y.rs test --use-backend llvm + bench: runs-on: ubuntu-latest timeout-minutes: 60 From 38b4b985984d6af2a2face7fef2e9b6c80be13d4 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 28 May 2023 09:11:07 +0000 Subject: [PATCH 48/89] Remove -preview tag from the llvm-tools component dependency --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index b8f06e0b4b1..e41da0ad491 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] channel = "nightly-2023-05-26" -components = ["rust-src", "rustc-dev", "llvm-tools-preview"] +components = ["rust-src", "rustc-dev", "llvm-tools"] From d91fabd44f61db4895921dee055d792b5a1e032f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 28 May 2023 09:55:04 +0000 Subject: [PATCH 49/89] Rustup to rustc 1.71.0-nightly (cca7ee581 2023-05-27) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index e41da0ad491..dfe51a092e3 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-05-26" +channel = "nightly-2023-05-28" components = ["rust-src", "rustc-dev", "llvm-tools"] From 62e603527d8fd16695c5a3958e4aaab925104fdb Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 28 May 2023 11:04:15 +0000 Subject: [PATCH 50/89] Don't explicitly remove needs-unwind tests Compiletest now respects panic=abort in the --print cfg output --- scripts/test_rustc_tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index db304332a9d..1b69be43086 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -11,12 +11,12 @@ pushd rust command -v rg >/dev/null 2>&1 || cargo install ripgrep rm -r tests/ui/{unsized-locals/,lto/,linkage*} || true -for test in $(rg --files-with-matches "lto|// needs-asm-support|// needs-unwind" tests/{codegen-units,ui,incremental}); do +for test in $(rg --files-with-matches "lto|// needs-asm-support" tests/{codegen-units,ui,incremental}); do rm $test done for test in tests/run-make/**/Makefile; do - if rg "# needs-asm-support|# needs-unwind" $test >/dev/null; then + if rg "# needs-asm-support" $test >/dev/null; then rm -r $(dirname $test) fi done From 4e87728772dbc8c99246165a6c1bdf46b44ad952 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Fri, 26 May 2023 11:19:35 -0600 Subject: [PATCH 51/89] Replace EarlyBinder(x) with EarlyBinder::new(x) --- src/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.rs b/src/common.rs index 5eaa988dd09..70cb6dfd66f 100644 --- a/src/common.rs +++ b/src/common.rs @@ -361,7 +361,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { self.instance.subst_mir_and_normalize_erasing_regions( self.tcx, ty::ParamEnv::reveal_all(), - ty::EarlyBinder(value), + ty::EarlyBinder::new(value), ) } From b4886251788ec79b7293ee5da347c17c8b1b0c23 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 29 May 2023 13:46:10 +0200 Subject: [PATCH 52/89] EarlyBinder::new -> EarlyBinder::bind --- src/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.rs b/src/common.rs index 70cb6dfd66f..67fd6d793e0 100644 --- a/src/common.rs +++ b/src/common.rs @@ -361,7 +361,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { self.instance.subst_mir_and_normalize_erasing_regions( self.tcx, ty::ParamEnv::reveal_all(), - ty::EarlyBinder::new(value), + ty::EarlyBinder::bind(value), ) } From 919da2f16ce207dfac883182e8f70ebcd7079b66 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Thu, 1 Jun 2023 00:01:25 -0700 Subject: [PATCH 53/89] remove unchecked_div/_rem from cg_cranelift --- src/intrinsics/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 0a513b08b74..1e83c30bd67 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -475,9 +475,7 @@ fn codegen_regular_intrinsic_call<'tcx>( sym::unchecked_add | sym::unchecked_sub | sym::unchecked_mul - | sym::unchecked_div | sym::exact_div - | sym::unchecked_rem | sym::unchecked_shl | sym::unchecked_shr => { intrinsic_args!(fx, args => (x, y); intrinsic); @@ -487,8 +485,7 @@ fn codegen_regular_intrinsic_call<'tcx>( sym::unchecked_add => BinOp::Add, sym::unchecked_sub => BinOp::Sub, sym::unchecked_mul => BinOp::Mul, - sym::unchecked_div | sym::exact_div => BinOp::Div, - sym::unchecked_rem => BinOp::Rem, + sym::exact_div => BinOp::Div, sym::unchecked_shl => BinOp::Shl, sym::unchecked_shr => BinOp::Shr, _ => unreachable!(), From fcd93accb49b21c908e2b86af9e5f9e5d90534bb Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 17 May 2023 10:30:14 +0000 Subject: [PATCH 54/89] Use translatable diagnostics in `rustc_const_eval` --- src/common.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/common.rs b/src/common.rs index 67fd6d793e0..7243cf6da23 100644 --- a/src/common.rs +++ b/src/common.rs @@ -6,6 +6,7 @@ use rustc_index::IndexVec; use rustc_middle::ty::layout::{ FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, }; +use rustc_span::source_map::Spanned; use rustc_span::SourceFile; use rustc_target::abi::call::FnAbi; use rustc_target::abi::{Integer, Primitive}; @@ -495,25 +496,16 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> { fn_abi_request: FnAbiRequest<'tcx>, ) -> ! { if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err { - self.0.sess.span_fatal(span, err.to_string()) + self.0.sess.emit_fatal(Spanned { span, node: err }) } else { match fn_abi_request { FnAbiRequest::OfFnPtr { sig, extra_args } => { - span_bug!( - span, - "`fn_abi_of_fn_ptr({}, {:?})` failed: {}", - sig, - extra_args, - err - ); + span_bug!(span, "`fn_abi_of_fn_ptr({sig}, {extra_args:?})` failed: {err:?}"); } FnAbiRequest::OfInstance { instance, extra_args } => { span_bug!( span, - "`fn_abi_of_instance({}, {:?})` failed: {}", - instance, - extra_args, - err + "`fn_abi_of_instance({instance}, {extra_args:?})` failed: {err:?}" ); } } From e369cce377219a8432b0e0748620aa6e455e1aea Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 2 Jun 2023 12:51:40 +0000 Subject: [PATCH 55/89] Rustup to rustc 1.72.0-nightly (d59363ad0 2023-06-01) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index dfe51a092e3..3aa8e29c211 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-05-28" +channel = "nightly-2023-06-02" components = ["rust-src", "rustc-dev", "llvm-tools"] From f8cde5884d94617044c8c40d24f9fe6f355fd73f Mon Sep 17 00:00:00 2001 From: Andrew Xie Date: Fri, 7 Apr 2023 15:56:33 -0400 Subject: [PATCH 56/89] Updated cranelift codegen to reflect modified trait signature --- src/driver/aot.rs | 4 ++-- src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index aad9a9647f8..d143bcc96ef 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -54,8 +54,8 @@ impl OngoingCodegen { self, sess: &Session, backend_config: &BackendConfig, - ) -> (CodegenResults, FxHashMap) { - let mut work_products = FxHashMap::default(); + ) -> (CodegenResults, FxIndexMap) { + let mut work_products = FxIndexMap::default(); let mut modules = vec![]; for module_codegen in self.modules { diff --git a/src/lib.rs b/src/lib.rs index 9966cc2ef3c..095fbe62c19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,7 +88,7 @@ mod prelude { }; pub(crate) use rustc_target::abi::{Abi, FieldIdx, Scalar, Size, VariantIdx, FIRST_VARIANT}; - pub(crate) use rustc_data_structures::fx::FxHashMap; + pub(crate) use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; pub(crate) use rustc_index::Idx; @@ -223,7 +223,7 @@ impl CodegenBackend for CraneliftCodegenBackend { ongoing_codegen: Box, sess: &Session, _outputs: &OutputFilenames, - ) -> Result<(CodegenResults, FxHashMap), ErrorGuaranteed> { + ) -> Result<(CodegenResults, FxIndexMap), ErrorGuaranteed> { Ok(ongoing_codegen .downcast::() .unwrap() From 76900705e8a54e8058a7d8f95da7fb873082c298 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 5 Jun 2023 08:55:43 +0000 Subject: [PATCH 57/89] Implement all vendor intrinsics used by regex on AVX2 systems This allows it to work with --sysroot llvm --- example/std_example.rs | 47 +++++++++++ src/intrinsics/llvm_x86.rs | 158 ++++++++++++++++++++++++++++++++++++- src/value_and_place.rs | 21 +++++ 3 files changed, 225 insertions(+), 1 deletion(-) diff --git a/example/std_example.rs b/example/std_example.rs index ab4045d11a6..811dbb267cd 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -198,6 +198,9 @@ unsafe fn test_simd() { test_mm_extract_epi8(); test_mm_insert_epi16(); + test_mm256_shuffle_epi8(); + test_mm256_permute2x128_si256(); + #[rustfmt::skip] let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))); assert_eq!(mask1, 1); @@ -293,6 +296,12 @@ pub unsafe fn assert_eq_m128d(a: __m128d, b: __m128d) { } } +#[cfg(target_arch = "x86_64")] +#[target_feature(enable = "avx")] +pub unsafe fn assert_eq_m256i(a: __m256i, b: __m256i) { + assert_eq!(std::mem::transmute::<_, [u64; 4]>(a), std::mem::transmute::<_, [u64; 4]>(b)) +} + #[cfg(target_arch = "x86_64")] #[target_feature(enable = "sse2")] unsafe fn test_mm_cvtsi128_si64() { @@ -336,6 +345,44 @@ unsafe fn test_mm_insert_epi16() { assert_eq_m128i(r, e); } +#[cfg(target_arch = "x86_64")] +#[target_feature(enable = "avx2")] +unsafe fn test_mm256_shuffle_epi8() { + #[rustfmt::skip] + let a = _mm256_setr_epi8( + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, + ); + #[rustfmt::skip] + let b = _mm256_setr_epi8( + 4, 128u8 as i8, 4, 3, 24, 12, 6, 19, + 12, 5, 5, 10, 4, 1, 8, 0, + 4, 128u8 as i8, 4, 3, 24, 12, 6, 19, + 12, 5, 5, 10, 4, 1, 8, 0, + ); + #[rustfmt::skip] + let expected = _mm256_setr_epi8( + 5, 0, 5, 4, 9, 13, 7, 4, + 13, 6, 6, 11, 5, 2, 9, 1, + 21, 0, 21, 20, 25, 29, 23, 20, + 29, 22, 22, 27, 21, 18, 25, 17, + ); + let r = _mm256_shuffle_epi8(a, b); + assert_eq_m256i(r, expected); +} + +#[cfg(target_arch = "x86_64")] +#[target_feature(enable = "avx2")] +unsafe fn test_mm256_permute2x128_si256() { + let a = _mm256_setr_epi64x(100, 200, 500, 600); + let b = _mm256_setr_epi64x(300, 400, 700, 800); + let r = _mm256_permute2x128_si256::<0b00_01_00_11>(a, b); + let e = _mm256_setr_epi64x(700, 800, 500, 600); + assert_eq_m256i(r, e); +} + fn test_checked_mul() { let u: Option = u8::from_str_radix("1000", 10).ok(); assert_eq!(u, None); diff --git a/src/intrinsics/llvm_x86.rs b/src/intrinsics/llvm_x86.rs index 8b6f8ca672d..bd80559abec 100644 --- a/src/intrinsics/llvm_x86.rs +++ b/src/intrinsics/llvm_x86.rs @@ -110,7 +110,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>( }; let a = codegen_operand(fx, a); let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8) - .expect("llvm.x86.sse2.psrli.d imm8 not const"); + .expect("llvm.x86.sse2.pslli.d imm8 not const"); simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8 .try_to_bits(Size::from_bytes(4)) @@ -120,6 +120,162 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>( _ => fx.bcx.ins().iconst(types::I32, 0), }); } + "llvm.x86.avx.psrli.d" => { + let (a, imm8) = match args { + [a, imm8] => (a, imm8), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8) + .expect("llvm.x86.avx.psrli.d imm8 not const"); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8 + .try_to_bits(Size::from_bytes(4)) + .unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) + { + imm8 if imm8 < 32 => fx.bcx.ins().ushr_imm(lane, i64::from(imm8 as u8)), + _ => fx.bcx.ins().iconst(types::I32, 0), + }); + } + "llvm.x86.avx.pslli.d" => { + let (a, imm8) = match args { + [a, imm8] => (a, imm8), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8) + .expect("llvm.x86.avx.pslli.d imm8 not const"); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8 + .try_to_bits(Size::from_bytes(4)) + .unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) + { + imm8 if imm8 < 32 => fx.bcx.ins().ishl_imm(lane, i64::from(imm8 as u8)), + _ => fx.bcx.ins().iconst(types::I32, 0), + }); + } + "llvm.x86.avx2.psrli.w" => { + let (a, imm8) = match args { + [a, imm8] => (a, imm8), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8) + .expect("llvm.x86.avx.psrli.w imm8 not const"); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8 + .try_to_bits(Size::from_bytes(4)) + .unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) + { + imm8 if imm8 < 16 => fx.bcx.ins().ushr_imm(lane, i64::from(imm8 as u8)), + _ => fx.bcx.ins().iconst(types::I32, 0), + }); + } + "llvm.x86.avx2.pslli.w" => { + let (a, imm8) = match args { + [a, imm8] => (a, imm8), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8) + .expect("llvm.x86.avx.pslli.w imm8 not const"); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8 + .try_to_bits(Size::from_bytes(4)) + .unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) + { + imm8 if imm8 < 16 => fx.bcx.ins().ishl_imm(lane, i64::from(imm8 as u8)), + _ => fx.bcx.ins().iconst(types::I32, 0), + }); + } + "llvm.x86.avx2.pshuf.b" => { + let (a, b) = match args { + [a, b] => (a, b), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let b = codegen_operand(fx, b); + + // Based on the pseudocode at https://github.com/rust-lang/stdarch/blob/1cfbca8b38fd9b4282b2f054f61c6ca69fc7ce29/crates/core_arch/src/x86/avx2.rs#L2319-L2332 + let zero = fx.bcx.ins().iconst(types::I8, 0); + for i in 0..16 { + let b_lane = b.value_lane(fx, i).load_scalar(fx); + let is_zero = fx.bcx.ins().band_imm(b_lane, 0x80); + let a_idx = fx.bcx.ins().band_imm(b_lane, 0xf); + let a_idx = fx.bcx.ins().uextend(fx.pointer_type, a_idx); + let a_lane = a.value_lane_dyn(fx, a_idx).load_scalar(fx); + let res = fx.bcx.ins().select(is_zero, zero, a_lane); + ret.place_lane(fx, i).to_ptr().store(fx, res, MemFlags::trusted()); + } + for i in 16..32 { + let b_lane = b.value_lane(fx, i).load_scalar(fx); + let is_zero = fx.bcx.ins().band_imm(b_lane, 0x80); + let b_lane_masked = fx.bcx.ins().band_imm(b_lane, 0xf); + let a_idx = fx.bcx.ins().iadd_imm(b_lane_masked, 16); + let a_idx = fx.bcx.ins().uextend(fx.pointer_type, a_idx); + let a_lane = a.value_lane_dyn(fx, a_idx).load_scalar(fx); + let res = fx.bcx.ins().select(is_zero, zero, a_lane); + ret.place_lane(fx, i).to_ptr().store(fx, res, MemFlags::trusted()); + } + } + "llvm.x86.avx2.vperm2i128" => { + // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_permute2x128_si256 + let (a, b, imm8) = match args { + [a, b, imm8] => (a, b, imm8), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let b = codegen_operand(fx, b); + let imm8 = codegen_operand(fx, imm8).load_scalar(fx); + + let a_0 = a.value_lane(fx, 0).load_scalar(fx); + let a_1 = a.value_lane(fx, 1).load_scalar(fx); + let a_low = fx.bcx.ins().iconcat(a_0, a_1); + let a_2 = a.value_lane(fx, 2).load_scalar(fx); + let a_3 = a.value_lane(fx, 3).load_scalar(fx); + let a_high = fx.bcx.ins().iconcat(a_2, a_3); + + let b_0 = b.value_lane(fx, 0).load_scalar(fx); + let b_1 = b.value_lane(fx, 1).load_scalar(fx); + let b_low = fx.bcx.ins().iconcat(b_0, b_1); + let b_2 = b.value_lane(fx, 2).load_scalar(fx); + let b_3 = b.value_lane(fx, 3).load_scalar(fx); + let b_high = fx.bcx.ins().iconcat(b_2, b_3); + + fn select4( + fx: &mut FunctionCx<'_, '_, '_>, + a_high: Value, + a_low: Value, + b_high: Value, + b_low: Value, + control: Value, + ) -> Value { + let a_or_b = fx.bcx.ins().band_imm(control, 0b0010); + let high_or_low = fx.bcx.ins().band_imm(control, 0b0001); + let is_zero = fx.bcx.ins().band_imm(control, 0b1000); + + let zero = fx.bcx.ins().iconst(types::I64, 0); + let zero = fx.bcx.ins().iconcat(zero, zero); + + let res_a = fx.bcx.ins().select(high_or_low, a_high, a_low); + let res_b = fx.bcx.ins().select(high_or_low, b_high, b_low); + let res = fx.bcx.ins().select(a_or_b, res_b, res_a); + fx.bcx.ins().select(is_zero, zero, res) + } + + let control0 = imm8; + let res_low = select4(fx, a_high, a_low, b_high, b_low, control0); + let (res_0, res_1) = fx.bcx.ins().isplit(res_low); + + let control1 = fx.bcx.ins().ushr_imm(imm8, 4); + let res_high = select4(fx, a_high, a_low, b_high, b_low, control1); + let (res_2, res_3) = fx.bcx.ins().isplit(res_high); + + ret.place_lane(fx, 0).to_ptr().store(fx, res_0, MemFlags::trusted()); + ret.place_lane(fx, 1).to_ptr().store(fx, res_1, MemFlags::trusted()); + ret.place_lane(fx, 2).to_ptr().store(fx, res_2, MemFlags::trusted()); + ret.place_lane(fx, 3).to_ptr().store(fx, res_3, MemFlags::trusted()); + } "llvm.x86.sse2.storeu.dq" => { intrinsic_args!(fx, args => (mem_addr, a); intrinsic); let mem_addr = mem_addr.load_scalar(fx); diff --git a/src/value_and_place.rs b/src/value_and_place.rs index b1fda6ff213..133c989b686 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -258,6 +258,27 @@ impl<'tcx> CValue<'tcx> { } } + /// Like [`CValue::value_lane`] except allowing a dynamically calculated lane index. + pub(crate) fn value_lane_dyn( + self, + fx: &mut FunctionCx<'_, '_, 'tcx>, + lane_idx: Value, + ) -> CValue<'tcx> { + let layout = self.1; + assert!(layout.ty.is_simd()); + let (_lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx); + let lane_layout = fx.layout_of(lane_ty); + match self.0 { + CValueInner::ByVal(_) | CValueInner::ByValPair(_, _) => unreachable!(), + CValueInner::ByRef(ptr, None) => { + let field_offset = fx.bcx.ins().imul_imm(lane_idx, lane_layout.size.bytes() as i64); + let field_ptr = ptr.offset_value(fx, field_offset); + CValue::by_ref(field_ptr, lane_layout) + } + CValueInner::ByRef(_, Some(_)) => unreachable!(), + } + } + /// If `ty` is signed, `const_val` must already be sign extended. pub(crate) fn const_val( fx: &mut FunctionCx<'_, '_, 'tcx>, From aeac484d18f285e0f647348a36d897d2e0aff38b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 5 Jun 2023 15:48:25 +0000 Subject: [PATCH 58/89] Run tests with LLVM sysroot in CI --- .github/workflows/main.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ed562d6ebe4..5dbdc00004e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -93,12 +93,6 @@ jobs: - name: Prepare dependencies run: ./y.rs prepare - - name: Build without unstable features - env: - TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} - # This is the config rust-lang/rust uses for builds - run: ./y.rs build --no-unstable-features - - name: Build run: ./y.rs build --sysroot none @@ -107,6 +101,15 @@ jobs: TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} run: ./y.rs test + - name: Install LLVM standard library + run: rustup target add ${{ matrix.env.TARGET_TRIPLE }} + + # This is roughly config rust-lang/rust uses for testing + - name: Test with LLVM sysroot + env: + TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} + run: ./y.rs test --sysroot llvm --no-unstable-features + # This job doesn't use cg_clif in any way. It checks that all cg_clif tests work with cg_llvm too. test_llvm: From 1797ae5174dc1444b2711ac250e1b44bf25ae1ef Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 5 Jun 2023 16:54:37 +0000 Subject: [PATCH 59/89] Define rust_eh_personality for alloc_example x86_64-pc-windows-gnu requires it to be defined. --- example/alloc_example.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/example/alloc_example.rs b/example/alloc_example.rs index d994e2fbc0a..117eed5afd8 100644 --- a/example/alloc_example.rs +++ b/example/alloc_example.rs @@ -1,4 +1,4 @@ -#![feature(start, core_intrinsics, alloc_error_handler)] +#![feature(start, core_intrinsics, alloc_error_handler, lang_items)] #![no_std] extern crate alloc; @@ -27,6 +27,11 @@ fn alloc_error_handler(_: alloc::alloc::Layout) -> ! { core::intrinsics::abort(); } +#[lang = "eh_personality"] +fn eh_personality() -> ! { + loop {} +} + #[start] fn main(_argc: isize, _argv: *const *const u8) -> isize { let world: Box<&str> = Box::new("Hello World!\0"); From 8fbd6f521a1375c7c3d62ed157e3c2dbb98f948e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 5 Jun 2023 17:20:59 +0000 Subject: [PATCH 60/89] Skip LLVM sysroot testing for native x86_64-pc-windows-gnu in CI It is way too slow and cross-compiled x86_64-pc-windows-gnu covers at least part of the tests. --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5dbdc00004e..abcd1affdee 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -106,6 +106,9 @@ jobs: # This is roughly config rust-lang/rust uses for testing - name: Test with LLVM sysroot + # Skip native x86_64-pc-windows-gnu. It is way too slow and cross-compiled + # x86_64-pc-windows-gnu covers at least part of the tests. + if: matrix.os != 'windows-latest' || matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu' env: TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} run: ./y.rs test --sysroot llvm --no-unstable-features From 11b3fc686c3483cbd551e5fdd3016568a7b720b8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 6 Jun 2023 08:20:44 +0000 Subject: [PATCH 61/89] Update object to 0.30.4 Fixes #1377 --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e411ff2887..904233d4242 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -277,9 +277,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "object" -version = "0.30.3" +version = "0.30.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" +checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" dependencies = [ "crc32fast", "hashbrown 0.13.2", From f36bb6d5298cf51ec505d38152858a4b4d3241a0 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 6 Jun 2023 09:04:05 +0000 Subject: [PATCH 62/89] Make unimplemented trap messages show up in more contexts --- src/trap.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/trap.rs b/src/trap.rs index 82a2ec57954..2fb0c2164c3 100644 --- a/src/trap.rs +++ b/src/trap.rs @@ -30,5 +30,9 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) { /// Trap code: user65535 pub(crate) fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRef) { codegen_print(fx, msg.as_ref()); + + let one = fx.bcx.ins().iconst(types::I32, 1); + fx.lib_call("exit", vec![AbiParam::new(types::I32)], vec![], &[one]); + fx.bcx.ins().trap(TrapCode::User(!0)); } From e4d0811360e79b2789f27a65eed7d3248e1e092c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 6 Jun 2023 09:14:07 +0000 Subject: [PATCH 63/89] Implement _mm_srli_epi16 and _mm_slli_epi16 --- src/intrinsics/llvm_x86.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/intrinsics/llvm_x86.rs b/src/intrinsics/llvm_x86.rs index bd80559abec..2202bf13808 100644 --- a/src/intrinsics/llvm_x86.rs +++ b/src/intrinsics/llvm_x86.rs @@ -120,6 +120,40 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>( _ => fx.bcx.ins().iconst(types::I32, 0), }); } + "llvm.x86.sse2.psrli.w" => { + let (a, imm8) = match args { + [a, imm8] => (a, imm8), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8) + .expect("llvm.x86.sse2.psrli.d imm8 not const"); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8 + .try_to_bits(Size::from_bytes(4)) + .unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) + { + imm8 if imm8 < 16 => fx.bcx.ins().ushr_imm(lane, i64::from(imm8 as u8)), + _ => fx.bcx.ins().iconst(types::I32, 0), + }); + } + "llvm.x86.sse2.pslli.w" => { + let (a, imm8) = match args { + [a, imm8] => (a, imm8), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8) + .expect("llvm.x86.sse2.pslli.d imm8 not const"); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8 + .try_to_bits(Size::from_bytes(4)) + .unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) + { + imm8 if imm8 < 16 => fx.bcx.ins().ishl_imm(lane, i64::from(imm8 as u8)), + _ => fx.bcx.ins().iconst(types::I32, 0), + }); + } "llvm.x86.avx.psrli.d" => { let (a, imm8) = match args { [a, imm8] => (a, imm8), From c09ef968782c8ada9aa5427605b1b7925ac60d32 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 6 Jun 2023 09:24:10 +0000 Subject: [PATCH 64/89] Implement _mm_shuffle_epi8 --- example/std_example.rs | 21 +++++++++++++++++++++ src/intrinsics/llvm_x86.rs | 23 +++++++++++++---------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/example/std_example.rs b/example/std_example.rs index 811dbb267cd..1bf0ff64c92 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -197,6 +197,7 @@ unsafe fn test_simd() { test_mm_extract_epi8(); test_mm_insert_epi16(); + test_mm_shuffle_epi8(); test_mm256_shuffle_epi8(); test_mm256_permute2x128_si256(); @@ -345,6 +346,26 @@ unsafe fn test_mm_insert_epi16() { assert_eq_m128i(r, e); } +#[cfg(target_arch = "x86_64")] +#[target_feature(enable = "ssse3")] +unsafe fn test_mm_shuffle_epi8() { + #[rustfmt::skip] + let a = _mm_setr_epi8( + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, + ); + #[rustfmt::skip] + let b = _mm_setr_epi8( + 4, 128_u8 as i8, 4, 3, + 24, 12, 6, 19, + 12, 5, 5, 10, + 4, 1, 8, 0, + ); + let expected = _mm_setr_epi8(5, 0, 5, 4, 9, 13, 7, 4, 13, 6, 6, 11, 5, 2, 9, 1); + let r = _mm_shuffle_epi8(a, b); + assert_eq_m128i(r, expected); +} + #[cfg(target_arch = "x86_64")] #[target_feature(enable = "avx2")] unsafe fn test_mm256_shuffle_epi8() { diff --git a/src/intrinsics/llvm_x86.rs b/src/intrinsics/llvm_x86.rs index 2202bf13808..bbd5f4be783 100644 --- a/src/intrinsics/llvm_x86.rs +++ b/src/intrinsics/llvm_x86.rs @@ -222,7 +222,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>( _ => fx.bcx.ins().iconst(types::I32, 0), }); } - "llvm.x86.avx2.pshuf.b" => { + "llvm.x86.ssse3.pshuf.b.128" | "llvm.x86.avx2.pshuf.b" => { let (a, b) = match args { [a, b] => (a, b), _ => bug!("wrong number of args for intrinsic {intrinsic}"), @@ -241,15 +241,18 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>( let res = fx.bcx.ins().select(is_zero, zero, a_lane); ret.place_lane(fx, i).to_ptr().store(fx, res, MemFlags::trusted()); } - for i in 16..32 { - let b_lane = b.value_lane(fx, i).load_scalar(fx); - let is_zero = fx.bcx.ins().band_imm(b_lane, 0x80); - let b_lane_masked = fx.bcx.ins().band_imm(b_lane, 0xf); - let a_idx = fx.bcx.ins().iadd_imm(b_lane_masked, 16); - let a_idx = fx.bcx.ins().uextend(fx.pointer_type, a_idx); - let a_lane = a.value_lane_dyn(fx, a_idx).load_scalar(fx); - let res = fx.bcx.ins().select(is_zero, zero, a_lane); - ret.place_lane(fx, i).to_ptr().store(fx, res, MemFlags::trusted()); + + if intrinsic == "llvm.x86.avx2.pshuf.b" { + for i in 16..32 { + let b_lane = b.value_lane(fx, i).load_scalar(fx); + let is_zero = fx.bcx.ins().band_imm(b_lane, 0x80); + let b_lane_masked = fx.bcx.ins().band_imm(b_lane, 0xf); + let a_idx = fx.bcx.ins().iadd_imm(b_lane_masked, 16); + let a_idx = fx.bcx.ins().uextend(fx.pointer_type, a_idx); + let a_lane = a.value_lane_dyn(fx, a_idx).load_scalar(fx); + let res = fx.bcx.ins().select(is_zero, zero, a_lane); + ret.place_lane(fx, i).to_ptr().store(fx, res, MemFlags::trusted()); + } } } "llvm.x86.avx2.vperm2i128" => { From 436bed8b7f775355d3fbd3eb722414a7aae67501 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 6 Jun 2023 14:12:03 +0000 Subject: [PATCH 65/89] Rustup to rustc 1.72.0-nightly (e6d4725c7 2023-06-05) --- build_sysroot/Cargo.lock | 8 ++++---- rust-toolchain | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index a41c783ed00..26b64211afb 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -128,9 +128,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.144" +version = "0.2.146" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" +checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" dependencies = [ "rustc-std-workspace-core", ] @@ -159,9 +159,9 @@ dependencies = [ [[package]] name = "object" -version = "0.30.3" +version = "0.30.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" +checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" dependencies = [ "compiler_builtins", "memchr", diff --git a/rust-toolchain b/rust-toolchain index 3aa8e29c211..151da5a6089 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-06-02" +channel = "nightly-2023-06-06" components = ["rust-src", "rustc-dev", "llvm-tools"] From 5d592ea79a6729ec2c06660225ebb5440a23704b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 13 Jun 2023 10:45:27 +0000 Subject: [PATCH 66/89] Rustup to rustc 1.72.0-nightly (df77afbca 2023-06-12) --- build_sysroot/Cargo.lock | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 26b64211afb..ef99acb8211 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -50,9 +50,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.92" +version = "0.1.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64518f1ae689f74db058bbfb3238dfe6eb53f59f4ae712f1ff4348628522e190" +checksum = "76630810d973ecea3dbf611e1b7aecfb1012751ef1ff8de3998f89014a166781" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index 151da5a6089..c5149b2696b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-06-06" +channel = "nightly-2023-06-13" components = ["rust-src", "rustc-dev", "llvm-tools"] From 45781e107c37524386478b02082700f09bd10d78 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 13 Jun 2023 12:31:34 +0000 Subject: [PATCH 67/89] Fix rustc test suite --- scripts/test_rustc_tests.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 1b69be43086..a7920cc54ea 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -116,6 +116,8 @@ rm tests/ui/lint/lint-const-item-mutation.rs # same rm tests/ui/pattern/usefulness/doc-hidden-non-exhaustive.rs # same rm tests/ui/suggestions/derive-trait-for-method-call.rs # same rm tests/ui/typeck/issue-46112.rs # same +rm tests/ui/consts/const_cmp_type_id.rs # same +rm tests/ui/consts/issue-73976-monomorphic.rs # same # rustdoc-clif passes extra args, suppressing the help message when no args are passed rm -r tests/run-make/issue-88756-default-output @@ -139,6 +141,7 @@ rm -r tests/run-make/multiple-emits # same rm -r tests/run-make/output-type-permutations # same rm -r tests/run-make/used # same rm -r tests/run-make/no-alloc-shim +rm -r tests/run-make/emit-to-stdout # bugs in the test suite # ====================== From 7886be6327772937d895c9738edb097b06d18b74 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Tue, 13 Jun 2023 15:06:39 +0200 Subject: [PATCH 68/89] remove patch from cranelift backend to ignore unwinding tests --- .../0023-coretests-Ignore-failing-tests.patch | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/patches/0023-coretests-Ignore-failing-tests.patch b/patches/0023-coretests-Ignore-failing-tests.patch index f2cb82751f0..385f5a8a2e0 100644 --- a/patches/0023-coretests-Ignore-failing-tests.patch +++ b/patches/0023-coretests-Ignore-failing-tests.patch @@ -10,42 +10,6 @@ Subject: [PATCH] [core] Ignore failing tests library/core/tests/time.rs | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) -diff --git a/array.rs b/array.rs -index 4bc44e9..8e3c7a4 100644 ---- a/array.rs -+++ b/array.rs -@@ -242,6 +242,7 @@ fn iterator_drops() { - assert_eq!(i.get(), 5); - } - -+/* - // This test does not work on targets without panic=unwind support. - // To work around this problem, test is marked is should_panic, so it will - // be automagically skipped on unsuitable targets, such as -@@ -283,6 +284,7 @@ fn array_default_impl_avoids_leaks_on_panic() { - assert_eq!(COUNTER.load(Relaxed), 0); - panic!("test succeeded") - } -+*/ - - #[test] - fn empty_array_is_always_default() { -@@ -304,6 +304,7 @@ fn array_map() { - assert_eq!(b, [1, 2, 3]); - } - -+/* - // See note on above test for why `should_panic` is used. - #[test] - #[should_panic(expected = "test succeeded")] -@@ -332,6 +333,7 @@ fn array_map_drop_safety() { - assert_eq!(DROPPED.load(Ordering::SeqCst), num_to_create); - panic!("test succeeded") - } -+*/ - - #[test] - fn cell_allows_array_cycle() { diff --git a/atomic.rs b/atomic.rs index 13b12db..96fe4b9 100644 --- a/atomic.rs From ce3f300e40146480d3f508e9657c454bf6881b10 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 13 Feb 2023 10:38:25 +0000 Subject: [PATCH 69/89] Add --download-dir option to specify download dir separate from --out-dir --- build_system/mod.rs | 12 ++++++++++-- build_system/usage.txt | 13 ++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/build_system/mod.rs b/build_system/mod.rs index 0110011169d..e1b46c3120e 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -81,6 +81,7 @@ pub(crate) fn main() { }; let mut out_dir = PathBuf::from("."); + let mut download_dir = None; let mut channel = "release"; let mut sysroot_kind = SysrootKind::Clif; let mut use_unstable_features = true; @@ -91,7 +92,12 @@ pub(crate) fn main() { "--out-dir" => { out_dir = PathBuf::from(args.next().unwrap_or_else(|| { arg_error!("--out-dir requires argument"); - })) + })); + } + "--download-dir" => { + download_dir = Some(PathBuf::from(args.next().unwrap_or_else(|| { + arg_error!("--download-dir requires argument"); + }))); } "--debug" => channel = "debug", "--sysroot" => { @@ -152,7 +158,9 @@ pub(crate) fn main() { out_dir = current_dir.join(out_dir); let dirs = path::Dirs { source_dir: current_dir.clone(), - download_dir: out_dir.join("download"), + download_dir: download_dir + .map(|dir| current_dir.join(dir)) + .unwrap_or_else(|| out_dir.join("download")), build_dir: out_dir.join("build"), dist_dir: out_dir.join("dist"), frozen, diff --git a/build_system/usage.txt b/build_system/usage.txt index 3bc18a93331..98726ae5af1 100644 --- a/build_system/usage.txt +++ b/build_system/usage.txt @@ -1,11 +1,11 @@ The build system of cg_clif. USAGE: - ./y.rs prepare [--out-dir DIR] - ./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] [--frozen] - ./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] [--frozen] - ./y.rs abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] [--frozen] - ./y.rs bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] [--frozen] + ./y.rs prepare [--out-dir DIR] [--download-dir DIR] + ./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.rs abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.rs bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] OPTIONS: --debug @@ -22,6 +22,9 @@ OPTIONS: Specify the directory in which the download, build and dist directories are stored. By default this is the working directory. + --download-dir DIR + Specify the directory in which the download directory is stored. Overrides --out-dir. + --no-unstable-features Some features are not yet ready for production usage. This option will disable these features. This includes the JIT mode and inline assembly support. From d0b8896189f5b2fb472d54ed389681dff97d907b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 15 Feb 2023 18:23:11 +0000 Subject: [PATCH 70/89] Allow building the build system using cargo Rust's build system only handles cargo, not rustc. --- .cirrus.yml | 4 ++-- .github/workflows/abi-cafe.yml | 6 +++--- .github/workflows/main.yml | 22 ++++++++++----------- .github/workflows/rustc.yml | 4 ++-- .gitignore | 1 + .vscode/settings.json | 3 ++- Cargo.toml | 8 -------- Readme.md | 8 ++++---- build_system/Cargo.lock | 7 +++++++ build_system/Cargo.toml | 13 +++++++++++++ build_system/build_sysroot.rs | 4 ++-- build_system/{mod.rs => main.rs} | 10 +++++++--- build_system/usage.txt | 16 ++++++++-------- clean_all.sh | 2 +- docs/usage.md | 2 +- scripts/rustup.sh | 2 +- scripts/setup_rust_fork.sh | 2 +- test.sh | 2 +- y.rs | 33 ++------------------------------ y.sh | 6 ++++++ 20 files changed, 75 insertions(+), 80 deletions(-) create mode 100644 build_system/Cargo.lock create mode 100644 build_system/Cargo.toml rename build_system/{mod.rs => main.rs} (98%) create mode 100755 y.sh diff --git a/.cirrus.yml b/.cirrus.yml index 1405ea74903..8b4efd4e394 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -10,7 +10,7 @@ task: folder: target prepare_script: - . $HOME/.cargo/env - - ./y.rs prepare + - ./y.sh prepare test_script: - . $HOME/.cargo/env - - ./y.rs test + - ./y.sh test diff --git a/.github/workflows/abi-cafe.yml b/.github/workflows/abi-cafe.yml index 3c40555669c..12aa69d3c79 100644 --- a/.github/workflows/abi-cafe.yml +++ b/.github/workflows/abi-cafe.yml @@ -46,12 +46,12 @@ jobs: run: rustup set default-host x86_64-pc-windows-gnu - name: Prepare dependencies - run: ./y.rs prepare + run: ./y.sh prepare - name: Build - run: ./y.rs build --sysroot none + run: ./y.sh build --sysroot none - name: Test abi-cafe env: TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} - run: ./y.rs abi-cafe + run: ./y.sh abi-cafe diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index abcd1affdee..8e6c1e8ade0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,7 @@ jobs: - name: Rustfmt run: | cargo fmt --check - rustfmt --check build_system/mod.rs + rustfmt --check build_system/main.rs rustfmt --check example/* @@ -91,15 +91,15 @@ jobs: sudo apt-get install -y gcc-s390x-linux-gnu qemu-user - name: Prepare dependencies - run: ./y.rs prepare + run: ./y.sh prepare - name: Build - run: ./y.rs build --sysroot none + run: ./y.sh build --sysroot none - name: Test env: TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} - run: ./y.rs test + run: ./y.sh test - name: Install LLVM standard library run: rustup target add ${{ matrix.env.TARGET_TRIPLE }} @@ -111,7 +111,7 @@ jobs: if: matrix.os != 'windows-latest' || matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu' env: TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} - run: ./y.rs test --sysroot llvm --no-unstable-features + run: ./y.sh test --sysroot llvm --no-unstable-features # This job doesn't use cg_clif in any way. It checks that all cg_clif tests work with cg_llvm too. @@ -165,13 +165,13 @@ jobs: run: cargo install hyperfine || true - name: Prepare dependencies - run: ./y.rs prepare + run: ./y.sh prepare - name: Build - run: CI_OPT=1 ./y.rs build --sysroot none + run: CI_OPT=1 ./y.sh build --sysroot none - name: Benchmark - run: CI_OPT=1 ./y.rs bench + run: CI_OPT=1 ./y.sh bench dist: @@ -224,13 +224,13 @@ jobs: sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable - name: Prepare dependencies - run: ./y.rs prepare + run: ./y.sh prepare - name: Build backend - run: CI_OPT=1 ./y.rs build --sysroot none + run: CI_OPT=1 ./y.sh build --sysroot none - name: Build sysroot - run: CI_OPT=1 ./y.rs build + run: CI_OPT=1 ./y.sh build - name: Package prebuilt cg_clif run: tar cvfJ cg_clif.tar.xz dist diff --git a/.github/workflows/rustc.yml b/.github/workflows/rustc.yml index b2f772c4fc4..b49dc3aff7a 100644 --- a/.github/workflows/rustc.yml +++ b/.github/workflows/rustc.yml @@ -18,7 +18,7 @@ jobs: key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} - name: Prepare dependencies - run: ./y.rs prepare + run: ./y.sh prepare - name: Test run: ./scripts/test_bootstrap.sh @@ -38,7 +38,7 @@ jobs: key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} - name: Prepare dependencies - run: ./y.rs prepare + run: ./y.sh prepare - name: Test run: ./scripts/test_rustc_tests.sh diff --git a/.gitignore b/.gitignore index e5d10a937ae..e6ac8c8408d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target +/build_system/target **/*.rs.bk *.rlib *.o diff --git a/.vscode/settings.json b/.vscode/settings.json index 7c8703cba50..60cb51d5663 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,9 +6,10 @@ "rust-analyzer.imports.granularity.enforce": true, "rust-analyzer.imports.granularity.group": "module", "rust-analyzer.imports.prefix": "crate", - "rust-analyzer.cargo.features": ["unstable-features", "__check_build_system_using_ra"], + "rust-analyzer.cargo.features": ["unstable-features"], "rust-analyzer.linkedProjects": [ "./Cargo.toml", + "./build_system/Cargo.toml", { "crates": [ { diff --git a/Cargo.toml b/Cargo.toml index 145b1150423..1c1f2d8577b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,13 +3,6 @@ name = "rustc_codegen_cranelift" version = "0.1.0" edition = "2021" -[[bin]] -# This is used just to teach rust-analyzer how to check the build system. required-features is used -# to disable it for regular builds. -name = "y" -path = "./y.rs" -required-features = ["__check_build_system_using_ra"] - [lib] crate-type = ["dylib"] @@ -45,7 +38,6 @@ smallvec = "1.8.1" unstable-features = ["jit", "inline_asm"] jit = ["cranelift-jit", "libloading"] inline_asm = [] -__check_build_system_using_ra = [] [package.metadata.rust-analyzer] rustc_private = true diff --git a/Readme.md b/Readme.md index 7e9945578a5..9469feea0cb 100644 --- a/Readme.md +++ b/Readme.md @@ -10,8 +10,8 @@ If not please open an issue. ```bash $ git clone https://github.com/bjorn3/rustc_codegen_cranelift $ cd rustc_codegen_cranelift -$ ./y.rs prepare -$ ./y.rs build +$ ./y.sh prepare +$ ./y.sh build ``` To run the test suite replace the last command with: @@ -20,7 +20,7 @@ To run the test suite replace the last command with: $ ./test.sh ``` -For more docs on how to build and test see [build_system/usage.txt](build_system/usage.txt) or the help message of `./y.rs`. +For more docs on how to build and test see [build_system/usage.txt](build_system/usage.txt) or the help message of `./y.sh`. ## Precompiled builds @@ -35,7 +35,7 @@ If you want to use `cargo clif build` instead of having to specify the full path rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects. -Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.rs prepare` and `y.rs build` or `test.sh`). +Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.sh prepare` and `y.sh build` or `test.sh`). In the directory with your project (where you can do the usual `cargo build`), run: diff --git a/build_system/Cargo.lock b/build_system/Cargo.lock new file mode 100644 index 00000000000..86268e19160 --- /dev/null +++ b/build_system/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "y" +version = "0.1.0" diff --git a/build_system/Cargo.toml b/build_system/Cargo.toml new file mode 100644 index 00000000000..f47b9bc5540 --- /dev/null +++ b/build_system/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "y" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "y" +path = "main.rs" + +[features] +unstable-features = [] # for rust-analyzer + +# Do not add any dependencies diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index dab9c77d1a4..2ed6272b2c5 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -225,7 +225,7 @@ fn build_clif_sysroot_for_triple( match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) { Err(e) => { eprintln!("Failed to get rustc version for patched sysroot source: {}", e); - eprintln!("Hint: Try `./y.rs prepare` to patch the sysroot source"); + eprintln!("Hint: Try `./y.sh prepare` to patch the sysroot source"); process::exit(1); } Ok(source_version) => { @@ -234,7 +234,7 @@ fn build_clif_sysroot_for_triple( eprintln!("The patched sysroot source is outdated"); eprintln!("Source version: {}", source_version.trim()); eprintln!("Rustc version: {}", rustc_version.trim()); - eprintln!("Hint: Try `./y.rs prepare` to update the patched sysroot source"); + eprintln!("Hint: Try `./y.sh prepare` to update the patched sysroot source"); process::exit(1); } } diff --git a/build_system/mod.rs b/build_system/main.rs similarity index 98% rename from build_system/mod.rs rename to build_system/main.rs index e1b46c3120e..06395eb141c 100644 --- a/build_system/mod.rs +++ b/build_system/main.rs @@ -1,3 +1,7 @@ +#![warn(rust_2018_idioms)] +#![warn(unused_lifetimes)] +#![warn(unreachable_pub)] + use std::env; use std::path::PathBuf; use std::process; @@ -37,19 +41,19 @@ enum Command { } #[derive(Copy, Clone, Debug)] -pub(crate) enum SysrootKind { +enum SysrootKind { None, Clif, Llvm, } #[derive(Clone, Debug)] -pub(crate) enum CodegenBackend { +enum CodegenBackend { Local(PathBuf), Builtin(String), } -pub(crate) fn main() { +fn main() { if env::var("RUST_BACKTRACE").is_err() { env::set_var("RUST_BACKTRACE", "1"); } diff --git a/build_system/usage.txt b/build_system/usage.txt index 98726ae5af1..9d20cdca6a7 100644 --- a/build_system/usage.txt +++ b/build_system/usage.txt @@ -1,11 +1,11 @@ The build system of cg_clif. USAGE: - ./y.rs prepare [--out-dir DIR] [--download-dir DIR] - ./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] - ./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] - ./y.rs abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] - ./y.rs bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.sh prepare [--out-dir DIR] [--download-dir DIR] + ./y.sh build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.sh test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.sh abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.sh bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] OPTIONS: --debug @@ -40,7 +40,7 @@ REQUIREMENTS: * Rustup: By default rustup is used to install the right nightly version. If you don't want to use rustup, you can manually install the nightly version indicated by rust-toolchain.toml and point the CARGO, RUSTC and RUSTDOC env vars to the right executables. - * Git: `./y.rs prepare` uses git for applying patches and on Windows for downloading test repos. - * Curl and tar (non-Windows only): Used by `./y.rs prepare` to download a single commit for + * Git: `./y.sh prepare` uses git for applying patches and on Windows for downloading test repos. + * Curl and tar (non-Windows only): Used by `./y.sh prepare` to download a single commit for repos. Git will be used to clone the whole repo when using Windows. - * [Hyperfine](https://github.com/sharkdp/hyperfine/): Used for benchmarking with `./y.rs bench`. + * [Hyperfine](https://github.com/sharkdp/hyperfine/): Used for benchmarking with `./y.sh bench`. diff --git a/clean_all.sh b/clean_all.sh index cdfc2e143e6..19405a53d1c 100755 --- a/clean_all.sh +++ b/clean_all.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -rm -rf target/ download/ build/ dist/ y.bin y.bin.dSYM y.exe y.pdb +rm -rf target/ build_system/target download/ build/ dist/ y.bin y.bin.dSYM y.exe y.pdb # Kept for now in case someone updates their checkout of cg_clif before running clean_all.sh # FIXME remove at some point in the future diff --git a/docs/usage.md b/docs/usage.md index 4c2b0fa1704..c6210f958d6 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -2,7 +2,7 @@ rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects. -Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.rs prepare` and `y.rs build` or `test.sh`). +Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.sh prepare` and `y.sh build` or `test.sh`). ## Cargo diff --git a/scripts/rustup.sh b/scripts/rustup.sh index 3cbeb6375de..6b446aafb7b 100755 --- a/scripts/rustup.sh +++ b/scripts/rustup.sh @@ -32,7 +32,7 @@ case $1 in ./clean_all.sh - ./y.rs prepare + ./y.sh prepare (cd download/sysroot && cargo update && cargo fetch && cp Cargo.lock ../../build_sysroot/) ;; diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index abb09775d21..15b16b42be5 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -./y.rs build --no-unstable-features +./y.sh build --no-unstable-features echo "[SETUP] Rust fork" git clone https://github.com/rust-lang/rust.git || true diff --git a/test.sh b/test.sh index 13e7784539d..6357eebf026 100755 --- a/test.sh +++ b/test.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -exec ./y.rs test "$@" +exec ./y.sh test "$@" diff --git a/y.rs b/y.rs index a68a10500f5..e806a64d943 100755 --- a/y.rs +++ b/y.rs @@ -1,35 +1,6 @@ #!/usr/bin/env bash #![deny(unsafe_code)] /*This line is ignored by bash # This block is ignored by rustc -set -e -echo "[BUILD] y.rs" 1>&2 -rustc $0 -o ${0/.rs/.bin} -Cdebuginfo=1 --edition 2021 -exec ${0/.rs/.bin} $@ +echo "Warning: y.rs is a deprecated alias for y.sh" 1>&2 +exec ./y.sh "$@" */ - -#![warn(rust_2018_idioms)] -#![warn(unused_lifetimes)] -#![warn(unreachable_pub)] - -//! The build system for cg_clif -//! -//! # Manual compilation -//! -//! If your system doesn't support shell scripts you can manually compile and run this file using -//! for example: -//! -//! ```shell -//! $ rustc y.rs -o y.bin -//! $ ./y.bin -//! ``` -//! -//! # Naming -//! -//! The name `y.rs` was chosen to not conflict with rustc's `x.py`. - -#[path = "build_system/mod.rs"] -mod build_system; - -fn main() { - build_system::main(); -} diff --git a/y.sh b/y.sh new file mode 100755 index 00000000000..bc925a23e2a --- /dev/null +++ b/y.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e +echo "[BUILD] build system" 1>&2 +rustc build_system/main.rs -o y.bin -Cdebuginfo=1 --edition 2021 +exec ./y.bin "$@" From 0e4139922e08c306620cf5c43721670c55f3684f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 14 Apr 2023 13:17:11 +0000 Subject: [PATCH 71/89] Put patched sources in build/ instead of download/ --- build_system/abi_cafe.rs | 2 +- build_system/build_sysroot.rs | 2 +- build_system/prepare.rs | 33 +++++++++++++++------------------ build_system/tests.rs | 8 ++++---- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index 9634430d116..ba15db9f966 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -7,7 +7,7 @@ use super::{CodegenBackend, SysrootKind}; static ABI_CAFE_REPO: GitRepo = GitRepo::github("Gankra", "abi-cafe", "4c6dc8c9c687e2b3a760ff2176ce236872b37212", "abi-cafe"); -static ABI_CAFE: CargoProject = CargoProject::new(&ABI_CAFE_REPO.source_dir(), "abi_cafe"); +static ABI_CAFE: CargoProject = CargoProject::new(&ABI_CAFE_REPO.source_dir(), "abi_cafe_target"); pub(crate) fn run( channel: &str, diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 2ed6272b2c5..7ceda34bfac 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -156,7 +156,7 @@ impl SysrootTarget { } pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot"); -pub(crate) static BUILD_SYSROOT: RelPath = RelPath::DOWNLOAD.join("sysroot"); +pub(crate) static BUILD_SYSROOT: RelPath = RelPath::BUILD.join("sysroot"); pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = BUILD_SYSROOT.join("rustc_version"); pub(crate) static SYSROOT_SRC: RelPath = BUILD_SYSROOT.join("sysroot_src"); pub(crate) static STANDARD_LIBRARY: CargoProject = diff --git a/build_system/prepare.rs b/build_system/prepare.rs index ac2dc47dd7f..7bb9eca2945 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -39,9 +39,6 @@ fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { let rustc_version = get_rustc_version(rustc); fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap(); - eprintln!("[GIT] init"); - init_git_repo(&SYSROOT_SRC.to_path(dirs)); - apply_patches(dirs, "stdlib", &SYSROOT_SRC.to_path(dirs)); } @@ -51,15 +48,13 @@ fn prepare_coretests(dirs: &Dirs, rustc: &Path) { eprintln!("[COPY] coretests src"); - fs::create_dir_all(LIBCORE_TESTS_SRC.to_path(dirs)).unwrap(); + // FIXME ensure builds error out or update the copy if any of the files copied here change + LIBCORE_TESTS_SRC.ensure_fresh(dirs); copy_dir_recursively( &sysroot_src_orig.join("library/core/tests"), &LIBCORE_TESTS_SRC.to_path(dirs), ); - eprintln!("[GIT] init"); - init_git_repo(&LIBCORE_TESTS_SRC.to_path(dirs)); - apply_patches(dirs, "coretests", &LIBCORE_TESTS_SRC.to_path(dirs)); } @@ -85,23 +80,23 @@ impl GitRepo { pub(crate) const fn source_dir(&self) -> RelPath { match self.url { - GitRepoUrl::Github { user: _, repo } => RelPath::DOWNLOAD.join(repo), + GitRepoUrl::Github { user: _, repo } => RelPath::BUILD.join(repo), } } pub(crate) fn fetch(&self, dirs: &Dirs) { + let download_dir = match self.url { + GitRepoUrl::Github { user: _, repo } => RelPath::DOWNLOAD.join(repo).to_path(dirs), + }; + let source_dir = self.source_dir(); match self.url { GitRepoUrl::Github { user, repo } => { - clone_repo_shallow_github( - dirs, - &self.source_dir().to_path(dirs), - user, - repo, - self.rev, - ); + clone_repo_shallow_github(dirs, &download_dir, user, repo, self.rev); } } - apply_patches(dirs, self.patch_name, &self.source_dir().to_path(dirs)); + source_dir.ensure_fresh(dirs); + copy_dir_recursively(&download_dir, &source_dir.to_path(dirs)); + apply_patches(dirs, self.patch_name, &source_dir.to_path(dirs)); } } @@ -118,6 +113,8 @@ fn clone_repo(download_dir: &Path, repo: &str, rev: &str) { let mut checkout_cmd = git_command(download_dir, "checkout"); checkout_cmd.arg("-q").arg(rev); spawn_and_wait(checkout_cmd); + + std::fs::remove_dir_all(download_dir.join(".git")).unwrap(); } fn clone_repo_shallow_github(dirs: &Dirs, download_dir: &Path, user: &str, repo: &str, rev: &str) { @@ -165,8 +162,6 @@ fn clone_repo_shallow_github(dirs: &Dirs, download_dir: &Path, user: &str, repo: // Rename unpacked dir to the expected name std::fs::rename(archive_dir, &download_dir).unwrap(); - init_git_repo(&download_dir); - // Cleanup std::fs::remove_file(archive_file).unwrap(); } @@ -206,6 +201,8 @@ fn get_patches(dirs: &Dirs, crate_name: &str) -> Vec { } fn apply_patches(dirs: &Dirs, crate_name: &str, target_dir: &Path) { + init_git_repo(&target_dir); + if crate_name == "" { return; } diff --git a/build_system/tests.rs b/build_system/tests.rs index 7efb960697e..f975e43b13d 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -97,12 +97,12 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ pub(crate) static RAND_REPO: GitRepo = GitRepo::github("rust-random", "rand", "50b9a447410860af8d6db9a208c3576886955874", "rand"); -pub(crate) static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand"); +pub(crate) static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand_target"); pub(crate) static REGEX_REPO: GitRepo = GitRepo::github("rust-lang", "regex", "32fed9429eafba0ae92a64b01796a0c5a75b88c8", "regex"); -pub(crate) static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex"); +pub(crate) static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex_target"); pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( "rust-lang", @@ -112,9 +112,9 @@ pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( ); pub(crate) static PORTABLE_SIMD: CargoProject = - CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable_simd"); + CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable_simd_target"); -pub(crate) static LIBCORE_TESTS_SRC: RelPath = RelPath::DOWNLOAD.join("coretests_src"); +pub(crate) static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests_src"); pub(crate) static LIBCORE_TESTS: CargoProject = CargoProject::new(&LIBCORE_TESTS_SRC, "core_tests"); From 75327f8587fad77a25cfe99e52376b6862d75b57 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 14 Apr 2023 13:49:41 +0000 Subject: [PATCH 72/89] Reuse existing download in y.sh prepare if fresh --- build_system/abi_cafe.rs | 10 ++++- build_system/bench.rs | 6 +-- build_system/prepare.rs | 87 +++++++++++++++++++++++++++++++++++----- build_system/tests.rs | 19 +++++++-- 4 files changed, 103 insertions(+), 19 deletions(-) diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index ba15db9f966..29c127bf50e 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -4,8 +4,13 @@ use super::prepare::GitRepo; use super::utils::{spawn_and_wait, CargoProject, Compiler}; use super::{CodegenBackend, SysrootKind}; -static ABI_CAFE_REPO: GitRepo = - GitRepo::github("Gankra", "abi-cafe", "4c6dc8c9c687e2b3a760ff2176ce236872b37212", "abi-cafe"); +static ABI_CAFE_REPO: GitRepo = GitRepo::github( + "Gankra", + "abi-cafe", + "4c6dc8c9c687e2b3a760ff2176ce236872b37212", + "588df6d66abbe105", + "abi-cafe", +); static ABI_CAFE: CargoProject = CargoProject::new(&ABI_CAFE_REPO.source_dir(), "abi_cafe_target"); @@ -18,6 +23,7 @@ pub(crate) fn run( bootstrap_host_compiler: &Compiler, ) { ABI_CAFE_REPO.fetch(dirs); + ABI_CAFE_REPO.patch(dirs); eprintln!("Building sysroot for abi-cafe"); build_sysroot::build_sysroot( diff --git a/build_system/bench.rs b/build_system/bench.rs index d24803eb7c6..2bb11800034 100644 --- a/build_system/bench.rs +++ b/build_system/bench.rs @@ -10,6 +10,7 @@ static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( "ebobby", "simple-raytracer", "804a7a21b9e673a482797aa289a18ed480e4d813", + "ad6f59a2331a3f56", "", ); @@ -24,9 +25,8 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) { std::process::exit(1); } - if !SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).exists() { - SIMPLE_RAYTRACER_REPO.fetch(dirs); - } + SIMPLE_RAYTRACER_REPO.fetch(dirs); + SIMPLE_RAYTRACER_REPO.patch(dirs); let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap(); diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 7bb9eca2945..b76164a1d00 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -10,14 +10,18 @@ use super::tests::LIBCORE_TESTS_SRC; use super::utils::{copy_dir_recursively, git_command, retry_spawn_and_wait, spawn_and_wait}; pub(crate) fn prepare(dirs: &Dirs, rustc: &Path) { - RelPath::DOWNLOAD.ensure_fresh(dirs); - - prepare_stdlib(dirs, rustc); - prepare_coretests(dirs, rustc); - + RelPath::DOWNLOAD.ensure_exists(dirs); super::tests::RAND_REPO.fetch(dirs); super::tests::REGEX_REPO.fetch(dirs); super::tests::PORTABLE_SIMD_REPO.fetch(dirs); + + // FIXME do this on the fly? + prepare_stdlib(dirs, rustc); + prepare_coretests(dirs, rustc); + + super::tests::RAND_REPO.patch(dirs); + super::tests::REGEX_REPO.patch(dirs); + super::tests::PORTABLE_SIMD_REPO.patch(dirs); } fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { @@ -61,6 +65,7 @@ fn prepare_coretests(dirs: &Dirs, rustc: &Path) { pub(crate) struct GitRepo { url: GitRepoUrl, rev: &'static str, + content_hash: &'static str, patch_name: &'static str, } @@ -68,14 +73,49 @@ enum GitRepoUrl { Github { user: &'static str, repo: &'static str }, } +// Note: This uses a hasher which is not cryptographically secure. This is fine as the hash is meant +// to protect against accidental modification and outdated downloads, not against manipulation. +fn hash_file(file: &std::path::Path) -> u64 { + let contents = std::fs::read(file).unwrap(); + #[allow(deprecated)] + let mut hasher = std::hash::SipHasher::new(); + std::hash::Hash::hash(&contents, &mut hasher); + std::hash::Hasher::finish(&hasher) +} + +fn hash_dir(dir: &std::path::Path) -> u64 { + let mut sub_hashes = std::collections::BTreeMap::new(); + for entry in std::fs::read_dir(dir).unwrap() { + let entry = entry.unwrap(); + if entry.file_type().unwrap().is_dir() { + sub_hashes + .insert(entry.file_name().to_str().unwrap().to_owned(), hash_dir(&entry.path())); + } else { + sub_hashes + .insert(entry.file_name().to_str().unwrap().to_owned(), hash_file(&entry.path())); + } + } + #[allow(deprecated)] + let mut hasher = std::hash::SipHasher::new(); + std::hash::Hash::hash(&sub_hashes, &mut hasher); + std::hash::Hasher::finish(&hasher) +} + impl GitRepo { pub(crate) const fn github( user: &'static str, repo: &'static str, rev: &'static str, + content_hash: &'static str, patch_name: &'static str, ) -> GitRepo { - GitRepo { url: GitRepoUrl::Github { user, repo }, rev, patch_name } + GitRepo { url: GitRepoUrl::Github { user, repo }, rev, content_hash, patch_name } + } + + fn download_dir(&self, dirs: &Dirs) -> PathBuf { + match self.url { + GitRepoUrl::Github { user: _, repo } => RelPath::DOWNLOAD.join(repo).to_path(dirs), + } } pub(crate) const fn source_dir(&self) -> RelPath { @@ -85,15 +125,42 @@ impl GitRepo { } pub(crate) fn fetch(&self, dirs: &Dirs) { - let download_dir = match self.url { - GitRepoUrl::Github { user: _, repo } => RelPath::DOWNLOAD.join(repo).to_path(dirs), - }; - let source_dir = self.source_dir(); + let download_dir = self.download_dir(dirs); + + if download_dir.exists() { + let actual_hash = format!("{:016x}", hash_dir(&download_dir)); + if actual_hash == self.content_hash { + println!("[FRESH] {}", download_dir.display()); + return; + } else { + println!( + "Mismatched content hash for {download_dir}: {actual_hash} != {content_hash}. Downloading again.", + download_dir = download_dir.display(), + content_hash = self.content_hash, + ); + } + } + match self.url { GitRepoUrl::Github { user, repo } => { clone_repo_shallow_github(dirs, &download_dir, user, repo, self.rev); } } + + let actual_hash = format!("{:016x}", hash_dir(&download_dir)); + if actual_hash != self.content_hash { + println!( + "Download of {download_dir} failed with mismatched content hash: {actual_hash} != {content_hash}", + download_dir = download_dir.display(), + content_hash = self.content_hash, + ); + std::process::exit(1); + } + } + + pub(crate) fn patch(&self, dirs: &Dirs) { + let download_dir = self.download_dir(dirs); + let source_dir = self.source_dir(); source_dir.ensure_fresh(dirs); copy_dir_recursively(&download_dir, &source_dir.to_path(dirs)); apply_patches(dirs, self.patch_name, &source_dir.to_path(dirs)); diff --git a/build_system/tests.rs b/build_system/tests.rs index f975e43b13d..e60f0a4c612 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -94,13 +94,23 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ // FIXME(rust-random/rand#1293): Newer rand versions fail to test on Windows. Update once this is // fixed. -pub(crate) static RAND_REPO: GitRepo = - GitRepo::github("rust-random", "rand", "50b9a447410860af8d6db9a208c3576886955874", "rand"); +pub(crate) static RAND_REPO: GitRepo = GitRepo::github( + "rust-random", + "rand", + "50b9a447410860af8d6db9a208c3576886955874", + "98b2276210b30e43", + "rand", +); pub(crate) static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand_target"); -pub(crate) static REGEX_REPO: GitRepo = - GitRepo::github("rust-lang", "regex", "32fed9429eafba0ae92a64b01796a0c5a75b88c8", "regex"); +pub(crate) static REGEX_REPO: GitRepo = GitRepo::github( + "rust-lang", + "regex", + "32fed9429eafba0ae92a64b01796a0c5a75b88c8", + "d6af6507d565aa66", + "regex", +); pub(crate) static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex_target"); @@ -108,6 +118,7 @@ pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( "rust-lang", "portable-simd", "ad8afa8c81273b3b49acbea38cd3bcf17a34cf2b", + "1ba291009510070b", "portable-simd", ); From 2c38effe286e1b68a2f1125598ece6c8887d7d49 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 28 May 2023 12:37:48 +0000 Subject: [PATCH 73/89] Don't patch in place in apply_patches This will make it easier to skip patching if unnecessary in the future --- build_system/prepare.rs | 42 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index b76164a1d00..0302946e654 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -7,7 +7,9 @@ use super::build_sysroot::{BUILD_SYSROOT, ORIG_BUILD_SYSROOT, SYSROOT_RUSTC_VERS use super::path::{Dirs, RelPath}; use super::rustc_info::{get_default_sysroot, get_rustc_version}; use super::tests::LIBCORE_TESTS_SRC; -use super::utils::{copy_dir_recursively, git_command, retry_spawn_and_wait, spawn_and_wait}; +use super::utils::{ + copy_dir_recursively, git_command, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait, +}; pub(crate) fn prepare(dirs: &Dirs, rustc: &Path) { RelPath::DOWNLOAD.ensure_exists(dirs); @@ -35,31 +37,24 @@ fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { copy_dir_recursively(&ORIG_BUILD_SYSROOT.to_path(dirs), &BUILD_SYSROOT.to_path(dirs)); fs::create_dir_all(SYSROOT_SRC.to_path(dirs).join("library")).unwrap(); - copy_dir_recursively( - &sysroot_src_orig.join("library"), - &SYSROOT_SRC.to_path(dirs).join("library"), - ); + + apply_patches(dirs, "stdlib", &sysroot_src_orig, &SYSROOT_SRC.to_path(dirs)); let rustc_version = get_rustc_version(rustc); fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap(); - - apply_patches(dirs, "stdlib", &SYSROOT_SRC.to_path(dirs)); } fn prepare_coretests(dirs: &Dirs, rustc: &Path) { let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust"); assert!(sysroot_src_orig.exists()); - eprintln!("[COPY] coretests src"); - // FIXME ensure builds error out or update the copy if any of the files copied here change - LIBCORE_TESTS_SRC.ensure_fresh(dirs); - copy_dir_recursively( + apply_patches( + dirs, + "coretests", &sysroot_src_orig.join("library/core/tests"), &LIBCORE_TESTS_SRC.to_path(dirs), ); - - apply_patches(dirs, "coretests", &LIBCORE_TESTS_SRC.to_path(dirs)); } pub(crate) struct GitRepo { @@ -159,11 +154,12 @@ impl GitRepo { } pub(crate) fn patch(&self, dirs: &Dirs) { - let download_dir = self.download_dir(dirs); - let source_dir = self.source_dir(); - source_dir.ensure_fresh(dirs); - copy_dir_recursively(&download_dir, &source_dir.to_path(dirs)); - apply_patches(dirs, self.patch_name, &source_dir.to_path(dirs)); + apply_patches( + dirs, + self.patch_name, + &self.download_dir(dirs), + &self.source_dir().to_path(dirs), + ); } } @@ -267,8 +263,14 @@ fn get_patches(dirs: &Dirs, crate_name: &str) -> Vec { patches } -fn apply_patches(dirs: &Dirs, crate_name: &str, target_dir: &Path) { - init_git_repo(&target_dir); +fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, target_dir: &Path) { + // FIXME avoid copy and patch if src, patches and target are unchanged + + remove_dir_if_exists(target_dir); + fs::create_dir_all(target_dir).unwrap(); + copy_dir_recursively(source_dir, target_dir); + + init_git_repo(target_dir); if crate_name == "" { return; From fc23a8a7e0fe32ef18214ced7ee79e111a40df69 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 28 May 2023 12:45:05 +0000 Subject: [PATCH 74/89] Lazily patch coretests --- build_system/prepare.rs | 17 +---------------- build_system/tests.rs | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 0302946e654..8cf51db1770 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -6,7 +6,6 @@ use std::process::Command; use super::build_sysroot::{BUILD_SYSROOT, ORIG_BUILD_SYSROOT, SYSROOT_RUSTC_VERSION, SYSROOT_SRC}; use super::path::{Dirs, RelPath}; use super::rustc_info::{get_default_sysroot, get_rustc_version}; -use super::tests::LIBCORE_TESTS_SRC; use super::utils::{ copy_dir_recursively, git_command, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait, }; @@ -19,7 +18,6 @@ pub(crate) fn prepare(dirs: &Dirs, rustc: &Path) { // FIXME do this on the fly? prepare_stdlib(dirs, rustc); - prepare_coretests(dirs, rustc); super::tests::RAND_REPO.patch(dirs); super::tests::REGEX_REPO.patch(dirs); @@ -44,19 +42,6 @@ fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap(); } -fn prepare_coretests(dirs: &Dirs, rustc: &Path) { - let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust"); - assert!(sysroot_src_orig.exists()); - - // FIXME ensure builds error out or update the copy if any of the files copied here change - apply_patches( - dirs, - "coretests", - &sysroot_src_orig.join("library/core/tests"), - &LIBCORE_TESTS_SRC.to_path(dirs), - ); -} - pub(crate) struct GitRepo { url: GitRepoUrl, rev: &'static str, @@ -263,7 +248,7 @@ fn get_patches(dirs: &Dirs, crate_name: &str) -> Vec { patches } -fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, target_dir: &Path) { +pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, target_dir: &Path) { // FIXME avoid copy and patch if src, patches and target are unchanged remove_dir_if_exists(target_dir); diff --git a/build_system/tests.rs b/build_system/tests.rs index e60f0a4c612..ec97be2b2d9 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -1,12 +1,14 @@ use super::build_sysroot; use super::config; use super::path::{Dirs, RelPath}; -use super::prepare::GitRepo; +use super::prepare::{apply_patches, GitRepo}; +use super::rustc_info::get_default_sysroot; use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler}; use super::{CodegenBackend, SysrootKind}; use std::env; use std::ffi::OsStr; use std::fs; +use std::path::PathBuf; use std::process::Command; static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::BUILD.join("example"); @@ -125,9 +127,9 @@ pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( pub(crate) static PORTABLE_SIMD: CargoProject = CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable_simd_target"); -pub(crate) static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests_src"); +static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests_src"); -pub(crate) static LIBCORE_TESTS: CargoProject = CargoProject::new(&LIBCORE_TESTS_SRC, "core_tests"); +static LIBCORE_TESTS: CargoProject = CargoProject::new(&LIBCORE_TESTS_SRC, "core_tests"); const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ TestCase::custom("test.rust-random/rand", &|runner| { @@ -145,6 +147,13 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ } }), TestCase::custom("test.libcore", &|runner| { + apply_patches( + &runner.dirs, + "coretests", + &runner.stdlib_source.join("library/core/tests"), + &LIBCORE_TESTS_SRC.to_path(&runner.dirs), + ); + LIBCORE_TESTS.clean(&runner.dirs); if runner.is_native { @@ -231,6 +240,10 @@ pub(crate) fn run_tests( rustup_toolchain_name: Option<&str>, target_triple: String, ) { + let stdlib_source = + get_default_sysroot(&bootstrap_host_compiler.rustc).join("lib/rustlib/src/rust"); + assert!(stdlib_source.exists()); + if config::get_bool("testsuite.no_sysroot") { let target_compiler = build_sysroot::build_sysroot( dirs, @@ -247,6 +260,7 @@ pub(crate) fn run_tests( target_compiler, use_unstable_features, bootstrap_host_compiler.triple == target_triple, + stdlib_source.clone(), ); BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs); @@ -277,6 +291,7 @@ pub(crate) fn run_tests( target_compiler, use_unstable_features, bootstrap_host_compiler.triple == target_triple, + stdlib_source, ); if run_base_sysroot { @@ -299,6 +314,7 @@ struct TestRunner { use_unstable_features: bool, dirs: Dirs, target_compiler: Compiler, + stdlib_source: PathBuf, } impl TestRunner { @@ -307,6 +323,7 @@ impl TestRunner { mut target_compiler: Compiler, use_unstable_features: bool, is_native: bool, + stdlib_source: PathBuf, ) -> Self { if let Ok(rustflags) = env::var("RUSTFLAGS") { target_compiler.rustflags.push(' '); @@ -327,7 +344,14 @@ impl TestRunner { && target_compiler.triple.contains("x86_64") && !target_compiler.triple.contains("windows"); - Self { is_native, jit_supported, use_unstable_features, dirs, target_compiler } + Self { + is_native, + jit_supported, + use_unstable_features, + dirs, + target_compiler, + stdlib_source, + } } fn run_testsuite(&self, tests: &[TestCase]) { From b9129c0d6bb1e2adffb368f5062d4198bce6a7c7 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 28 May 2023 13:00:28 +0000 Subject: [PATCH 75/89] Rename a couple of build dirs for consistency --- build_system/tests.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build_system/tests.rs b/build_system/tests.rs index ec97be2b2d9..5502e2a23c6 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -125,11 +125,11 @@ pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( ); pub(crate) static PORTABLE_SIMD: CargoProject = - CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable_simd_target"); + CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable-simd_target"); -static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests_src"); +static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests"); -static LIBCORE_TESTS: CargoProject = CargoProject::new(&LIBCORE_TESTS_SRC, "core_tests"); +static LIBCORE_TESTS: CargoProject = CargoProject::new(&LIBCORE_TESTS_SRC, "coretests_target"); const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ TestCase::custom("test.rust-random/rand", &|runner| { From 54eaa5382c8455be4390c7e1e1b9b9f86c5a159d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 28 May 2023 17:57:49 +0000 Subject: [PATCH 76/89] Enable compiler-builtins no-asm feature using --features flag --- build_sysroot/Cargo.lock | 1 - build_sysroot/Cargo.toml | 2 -- build_sysroot/src/lib.rs | 2 +- build_system/build_sysroot.rs | 1 + 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index ef99acb8211..934665a0537 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -270,7 +270,6 @@ name = "sysroot" version = "0.0.0" dependencies = [ "alloc", - "compiler_builtins", "core", "proc_macro", "std", diff --git a/build_sysroot/Cargo.toml b/build_sysroot/Cargo.toml index ea9d1c8df1c..194a5f27275 100644 --- a/build_sysroot/Cargo.toml +++ b/build_sysroot/Cargo.toml @@ -9,8 +9,6 @@ std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtra test = { path = "./sysroot_src/library/test" } proc_macro = { path = "./sysroot_src/library/proc_macro" } -compiler_builtins = { version = "0.1.87", default-features = false, features = ["no-asm"] } - [patch.crates-io] rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-core" } rustc-std-workspace-alloc = { path = "./sysroot_src/library/rustc-std-workspace-alloc" } diff --git a/build_sysroot/src/lib.rs b/build_sysroot/src/lib.rs index 0c9ac1ac8e4..8b137891791 100644 --- a/build_sysroot/src/lib.rs +++ b/build_sysroot/src/lib.rs @@ -1 +1 @@ -#![no_std] + diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 7ceda34bfac..5c1e30d4eef 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -277,6 +277,7 @@ fn build_clif_sysroot_for_triple( if channel == "release" { build_cmd.arg("--release"); } + build_cmd.arg("--features").arg("std/compiler-builtins-no-asm"); build_cmd.arg("--locked"); build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); if compiler.triple.contains("apple") { From 3baee66f9b0cd440d9288ce757cc6caec93eeb67 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 29 May 2023 09:58:59 +0000 Subject: [PATCH 77/89] Rework standard library building --- build_sysroot/Cargo.lock | 104 +++++++++++++++++++++++++++++++++- build_sysroot/Cargo.toml | 18 ++---- build_sysroot/src/lib.rs | 1 - build_system/build_sysroot.rs | 11 ++-- build_system/prepare.rs | 13 ++--- 5 files changed, 117 insertions(+), 30 deletions(-) delete mode 100644 build_sysroot/src/lib.rs diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 934665a0537..1dde9e54d7e 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -30,8 +30,26 @@ version = "0.0.0" dependencies = [ "compiler_builtins", "core", + "rand", + "rand_xorshift", ] +[[package]] +name = "auxv" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e50430f9beb8effb02399fa81c76eeaa26b05e4f03b09285cad8d079c1af5a3d" +dependencies = [ + "byteorder", + "gcc", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "cc" version = "1.0.79" @@ -54,12 +72,27 @@ version = "0.1.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76630810d973ecea3dbf611e1b7aecfb1012751ef1ff8de3998f89014a166781" dependencies = [ + "cc", "rustc-std-workspace-core", ] [[package]] name = "core" version = "0.0.0" +dependencies = [ + "rand", + "rand_xorshift", +] + +[[package]] +name = "cupid" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bad352a84b567cc38a5854e3aa8ee903cb8519a25d0b799b739bafffd1f91a1" +dependencies = [ + "gcc", + "rustc_version", +] [[package]] name = "dlmalloc" @@ -82,6 +115,12 @@ dependencies = [ "rustc-std-workspace-core", ] +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + [[package]] name = "getopts" version = "0.2.21" @@ -200,6 +239,39 @@ dependencies = [ "std", ] +[[package]] +name = "profiler_builtins" +version = "0.0.0" +dependencies = [ + "cc", + "compiler_builtins", + "core", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -231,6 +303,30 @@ dependencies = [ "std", ] +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "std" version = "0.0.0" @@ -249,6 +345,9 @@ dependencies = [ "object", "panic_abort", "panic_unwind", + "profiler_builtins", + "rand", + "rand_xorshift", "rustc-demangle", "std_detect", "unwind", @@ -259,8 +358,11 @@ dependencies = [ name = "std_detect" version = "0.1.5" dependencies = [ + "auxv", "cfg-if", "compiler_builtins", + "cupid", + "libc", "rustc-std-workspace-alloc", "rustc-std-workspace-core", ] @@ -269,8 +371,6 @@ dependencies = [ name = "sysroot" version = "0.0.0" dependencies = [ - "alloc", - "core", "proc_macro", "std", "test", diff --git a/build_sysroot/Cargo.toml b/build_sysroot/Cargo.toml index 194a5f27275..3e5d0c159f2 100644 --- a/build_sysroot/Cargo.toml +++ b/build_sysroot/Cargo.toml @@ -1,18 +1,10 @@ -[package] -name = "sysroot" -version = "0.0.0" - -[dependencies] -core = { path = "./sysroot_src/library/core" } -alloc = { path = "./sysroot_src/library/alloc" } -std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] } -test = { path = "./sysroot_src/library/test" } -proc_macro = { path = "./sysroot_src/library/proc_macro" } +[workspace] +members = ["./library/sysroot"] [patch.crates-io] -rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-core" } -rustc-std-workspace-alloc = { path = "./sysroot_src/library/rustc-std-workspace-alloc" } -rustc-std-workspace-std = { path = "./sysroot_src/library/rustc-std-workspace-std" } +rustc-std-workspace-core = { path = "./library/rustc-std-workspace-core" } +rustc-std-workspace-alloc = { path = "./library/rustc-std-workspace-alloc" } +rustc-std-workspace-std = { path = "./library/rustc-std-workspace-std" } [profile.dev] lto = "off" diff --git a/build_sysroot/src/lib.rs b/build_sysroot/src/lib.rs deleted file mode 100644 index 8b137891791..00000000000 --- a/build_sysroot/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 5c1e30d4eef..09dc43b8136 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -156,11 +156,10 @@ impl SysrootTarget { } pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot"); -pub(crate) static BUILD_SYSROOT: RelPath = RelPath::BUILD.join("sysroot"); -pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = BUILD_SYSROOT.join("rustc_version"); -pub(crate) static SYSROOT_SRC: RelPath = BUILD_SYSROOT.join("sysroot_src"); +pub(crate) static STDLIB_SRC: RelPath = RelPath::BUILD.join("stdlib"); +pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = STDLIB_SRC.join("rustc_version"); pub(crate) static STANDARD_LIBRARY: CargoProject = - CargoProject::new(&BUILD_SYSROOT, "build_sysroot"); + CargoProject::new(&STDLIB_SRC.join("library/sysroot"), "stdlib_target"); pub(crate) static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup"); #[must_use] @@ -277,7 +276,7 @@ fn build_clif_sysroot_for_triple( if channel == "release" { build_cmd.arg("--release"); } - build_cmd.arg("--features").arg("std/compiler-builtins-no-asm"); + build_cmd.arg("--features").arg("compiler-builtins-no-asm backtrace panic-unwind"); build_cmd.arg("--locked"); build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); if compiler.triple.contains("apple") { @@ -307,7 +306,7 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option { RTSTARTUP_SYSROOT.ensure_fresh(dirs); - let rtstartup_src = SYSROOT_SRC.to_path(dirs).join("library").join("rtstartup"); + let rtstartup_src = STDLIB_SRC.to_path(dirs).join("library").join("rtstartup"); let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] }; for file in ["rsbegin", "rsend"] { diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 8cf51db1770..bc249f4cdab 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -3,7 +3,7 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; -use super::build_sysroot::{BUILD_SYSROOT, ORIG_BUILD_SYSROOT, SYSROOT_RUSTC_VERSION, SYSROOT_SRC}; +use super::build_sysroot::{ORIG_BUILD_SYSROOT, STDLIB_SRC, SYSROOT_RUSTC_VERSION}; use super::path::{Dirs, RelPath}; use super::rustc_info::{get_default_sysroot, get_rustc_version}; use super::utils::{ @@ -28,15 +28,10 @@ fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust"); assert!(sysroot_src_orig.exists()); - eprintln!("[COPY] stdlib src"); + apply_patches(dirs, "stdlib", &sysroot_src_orig, &STDLIB_SRC.to_path(dirs)); // FIXME ensure builds error out or update the copy if any of the files copied here change - BUILD_SYSROOT.ensure_fresh(dirs); - copy_dir_recursively(&ORIG_BUILD_SYSROOT.to_path(dirs), &BUILD_SYSROOT.to_path(dirs)); - - fs::create_dir_all(SYSROOT_SRC.to_path(dirs).join("library")).unwrap(); - - apply_patches(dirs, "stdlib", &sysroot_src_orig, &SYSROOT_SRC.to_path(dirs)); + copy_dir_recursively(&ORIG_BUILD_SYSROOT.to_path(dirs), &STDLIB_SRC.to_path(dirs)); let rustc_version = get_rustc_version(rustc); fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap(); @@ -251,6 +246,8 @@ fn get_patches(dirs: &Dirs, crate_name: &str) -> Vec { pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, target_dir: &Path) { // FIXME avoid copy and patch if src, patches and target are unchanged + eprintln!("[COPY] {crate_name} source"); + remove_dir_if_exists(target_dir); fs::create_dir_all(target_dir).unwrap(); copy_dir_recursively(source_dir, target_dir); From 67f9fe6863cede6ca5f41b938e4f3188feb24c65 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 29 May 2023 11:51:37 +0000 Subject: [PATCH 78/89] Lazily patch all test projects --- build_system/prepare.rs | 4 ---- build_system/tests.rs | 8 ++++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index bc249f4cdab..115575bff51 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -18,10 +18,6 @@ pub(crate) fn prepare(dirs: &Dirs, rustc: &Path) { // FIXME do this on the fly? prepare_stdlib(dirs, rustc); - - super::tests::RAND_REPO.patch(dirs); - super::tests::REGEX_REPO.patch(dirs); - super::tests::PORTABLE_SIMD_REPO.patch(dirs); } fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { diff --git a/build_system/tests.rs b/build_system/tests.rs index 5502e2a23c6..d104efd61e5 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -133,6 +133,8 @@ static LIBCORE_TESTS: CargoProject = CargoProject::new(&LIBCORE_TESTS_SRC, "core const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ TestCase::custom("test.rust-random/rand", &|runner| { + RAND_REPO.patch(&runner.dirs); + RAND.clean(&runner.dirs); if runner.is_native { @@ -168,6 +170,8 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ } }), TestCase::custom("test.regex-shootout-regex-dna", &|runner| { + REGEX_REPO.patch(&runner.dirs); + REGEX.clean(&runner.dirs); let mut build_cmd = REGEX.build(&runner.target_compiler, &runner.dirs); @@ -200,6 +204,8 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ } }), TestCase::custom("test.regex", &|runner| { + REGEX_REPO.patch(&runner.dirs); + REGEX.clean(&runner.dirs); if runner.is_native { @@ -216,6 +222,8 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ } }), TestCase::custom("test.portable-simd", &|runner| { + PORTABLE_SIMD_REPO.patch(&runner.dirs); + PORTABLE_SIMD.clean(&runner.dirs); let mut build_cmd = PORTABLE_SIMD.build(&runner.target_compiler, &runner.dirs); From d3da972441f6efd16c1b1aa5c2672cc218949bdb Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 29 May 2023 12:19:38 +0000 Subject: [PATCH 79/89] Write stdlib workspace Cargo.toml directly in prepare.rs --- build_sysroot/Cargo.toml | 26 -------------------------- build_system/prepare.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 26 deletions(-) delete mode 100644 build_sysroot/Cargo.toml diff --git a/build_sysroot/Cargo.toml b/build_sysroot/Cargo.toml deleted file mode 100644 index 3e5d0c159f2..00000000000 --- a/build_sysroot/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[workspace] -members = ["./library/sysroot"] - -[patch.crates-io] -rustc-std-workspace-core = { path = "./library/rustc-std-workspace-core" } -rustc-std-workspace-alloc = { path = "./library/rustc-std-workspace-alloc" } -rustc-std-workspace-std = { path = "./library/rustc-std-workspace-std" } - -[profile.dev] -lto = "off" - -[profile.release] -debug = true -incremental = true -lto = "off" - -# Mandatory for correctly compiling compiler-builtins -[profile.dev.package.compiler_builtins] -debug-assertions = false -overflow-checks = false -codegen-units = 10000 - -[profile.release.package.compiler_builtins] -debug-assertions = false -overflow-checks = false -codegen-units = 10000 diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 115575bff51..4f26cb5e85f 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -29,6 +29,39 @@ fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { // FIXME ensure builds error out or update the copy if any of the files copied here change copy_dir_recursively(&ORIG_BUILD_SYSROOT.to_path(dirs), &STDLIB_SRC.to_path(dirs)); + std::fs::write( + STDLIB_SRC.to_path(dirs).join("Cargo.toml"), + r#" +[workspace] +members = ["./library/sysroot"] + +[patch.crates-io] +rustc-std-workspace-core = { path = "./library/rustc-std-workspace-core" } +rustc-std-workspace-alloc = { path = "./library/rustc-std-workspace-alloc" } +rustc-std-workspace-std = { path = "./library/rustc-std-workspace-std" } + +[profile.dev] +lto = "off" + +[profile.release] +debug = true +incremental = true +lto = "off" + +# Mandatory for correctly compiling compiler-builtins +[profile.dev.package.compiler_builtins] +debug-assertions = false +overflow-checks = false +codegen-units = 10000 + +[profile.release.package.compiler_builtins] +debug-assertions = false +overflow-checks = false +codegen-units = 10000 +"#, + ) + .unwrap(); + let rustc_version = get_rustc_version(rustc); fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap(); } From 8ad9e9f861c9cbdd85c99df73a4a2d03a0d15014 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 29 May 2023 12:09:40 +0000 Subject: [PATCH 80/89] Ensure everything has a lockfile --- build_system/build_sysroot.rs | 2 - build_system/prepare.rs | 13 +- build_system/utils.rs | 3 +- patches/coretests-lock.toml | 35 ++ patches/portable-simd-lock.toml | 304 ++++++++++++ patches/rand-lock.toml | 346 ++++++++++++++ patches/regex-lock.toml | 439 ++++++++++++++++++ .../Cargo.lock => patches/stdlib-lock.toml | 0 scripts/rustup.sh | 4 +- 9 files changed, 1136 insertions(+), 10 deletions(-) create mode 100644 patches/coretests-lock.toml create mode 100644 patches/portable-simd-lock.toml create mode 100644 patches/rand-lock.toml create mode 100644 patches/regex-lock.toml rename build_sysroot/Cargo.lock => patches/stdlib-lock.toml (100%) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 09dc43b8136..1045023c361 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -155,7 +155,6 @@ impl SysrootTarget { } } -pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot"); pub(crate) static STDLIB_SRC: RelPath = RelPath::BUILD.join("stdlib"); pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = STDLIB_SRC.join("rustc_version"); pub(crate) static STANDARD_LIBRARY: CargoProject = @@ -277,7 +276,6 @@ fn build_clif_sysroot_for_triple( build_cmd.arg("--release"); } build_cmd.arg("--features").arg("compiler-builtins-no-asm backtrace panic-unwind"); - build_cmd.arg("--locked"); build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); if compiler.triple.contains("apple") { build_cmd.env("CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO", "packed"); diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 4f26cb5e85f..c6bc796f3a9 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -3,7 +3,7 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; -use super::build_sysroot::{ORIG_BUILD_SYSROOT, STDLIB_SRC, SYSROOT_RUSTC_VERSION}; +use super::build_sysroot::{STDLIB_SRC, SYSROOT_RUSTC_VERSION}; use super::path::{Dirs, RelPath}; use super::rustc_info::{get_default_sysroot, get_rustc_version}; use super::utils::{ @@ -26,9 +26,6 @@ fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { apply_patches(dirs, "stdlib", &sysroot_src_orig, &STDLIB_SRC.to_path(dirs)); - // FIXME ensure builds error out or update the copy if any of the files copied here change - copy_dir_recursively(&ORIG_BUILD_SYSROOT.to_path(dirs), &STDLIB_SRC.to_path(dirs)); - std::fs::write( STDLIB_SRC.to_path(dirs).join("Cargo.toml"), r#" @@ -297,4 +294,12 @@ pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, ta apply_patch_cmd.arg(patch).arg("-q"); spawn_and_wait(apply_patch_cmd); } + + let source_lockfile = RelPath::PATCHES.to_path(dirs).join(format!("{crate_name}-lock.toml")); + let target_lockfile = target_dir.join("Cargo.lock"); + if source_lockfile.exists() { + fs::copy(source_lockfile, target_lockfile).unwrap(); + } else { + assert!(target_lockfile.exists()); + } } diff --git a/build_system/utils.rs b/build_system/utils.rs index 3e12ed22ef6..e7fcb2644d7 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -81,7 +81,8 @@ impl CargoProject { .arg("--manifest-path") .arg(self.manifest_path(dirs)) .arg("--target-dir") - .arg(self.target_dir(dirs)); + .arg(self.target_dir(dirs)) + .arg("--locked"); if dirs.frozen { cmd.arg("--frozen"); diff --git a/patches/coretests-lock.toml b/patches/coretests-lock.toml new file mode 100644 index 00000000000..af8f28a193b --- /dev/null +++ b/patches/coretests-lock.toml @@ -0,0 +1,35 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "coretests" +version = "0.0.0" +dependencies = [ + "rand", + "rand_xorshift", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core", +] diff --git a/patches/portable-simd-lock.toml b/patches/portable-simd-lock.toml new file mode 100644 index 00000000000..e7db1fd2c7f --- /dev/null +++ b/patches/portable-simd-lock.toml @@ -0,0 +1,304 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bumpalo" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "core_simd" +version = "0.1.0" +dependencies = [ + "proptest", + "std_float", + "test_helpers", + "wasm-bindgen", + "wasm-bindgen-test", +] + +[[package]] +name = "js-sys" +version = "0.3.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "log" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proptest" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12e6c80c1139113c28ee4670dc50cc42915228b51f56a9e407f0ec60f966646f" +dependencies = [ + "bitflags", + "byteorder", + "num-traits", + "rand", + "rand_chacha", + "rand_xorshift", +] + +[[package]] +name = "quote" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rand_xorshift" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77d416b86801d23dde1aa643023b775c3a462efc0ed96443add11546cdf1dca8" +dependencies = [ + "rand_core", +] + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "std_float" +version = "0.1.0" +dependencies = [ + "core_simd", +] + +[[package]] +name = "syn" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "test_helpers" +version = "0.1.0" +dependencies = [ + "proptest", +] + +[[package]] +name = "unicode-ident" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + +[[package]] +name = "wasm-bindgen" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d1985d03709c53167ce907ff394f5316aa22cb4e12761295c5dc57dacb6297e" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93" + +[[package]] +name = "wasm-bindgen-test" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e636f3a428ff62b3742ebc3c70e254dfe12b8c2b469d688ea59cdd4abcf502" +dependencies = [ + "console_error_panic_hook", + "js-sys", + "scoped-tls", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test-macro", +] + +[[package]] +name = "wasm-bindgen-test-macro" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f18c1fad2f7c4958e7bcce014fa212f59a65d5e3721d0f77e6c0b27ede936ba3" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "web-sys" +version = "0.3.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bdd9ef4e984da1187bf8110c5cf5b845fbc87a23602cdf912386a76fcd3a7c2" +dependencies = [ + "js-sys", + "wasm-bindgen", +] diff --git a/patches/rand-lock.toml b/patches/rand-lock.toml new file mode 100644 index 00000000000..66c515731c5 --- /dev/null +++ b/patches/rand-lock.toml @@ -0,0 +1,346 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "average" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843ec791d3f24503bbf72bbd5e49a3ab4dbb4bcd0a8ef6b0c908efa73caa27b1" +dependencies = [ + "easy-cast", + "float-ord", + "num-traits", +] + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "easy-cast" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bd102ee8c418348759919b83b81cdbdc933ffe29740b903df448b4bafaa348e" +dependencies = [ + "libm", +] + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "float-ord" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce81f49ae8a0482e4c55ea62ebbd7e5a686af544c00b9d090bba3ff9be97b3d" + +[[package]] +name = "getrandom" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "libc" +version = "0.2.144" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" + +[[package]] +name = "libm" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" + +[[package]] +name = "log" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" + +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.9.0" +dependencies = [ + "bincode", + "libc", + "log", + "rand_chacha", + "rand_core", + "rand_pcg", + "rayon", + "serde", +] + +[[package]] +name = "rand_chacha" +version = "0.4.0" +dependencies = [ + "ppv-lite86", + "rand_core", + "serde", + "serde_json", +] + +[[package]] +name = "rand_core" +version = "0.7.0" +dependencies = [ + "getrandom", + "serde", +] + +[[package]] +name = "rand_distr" +version = "0.5.0" +dependencies = [ + "average", + "num-traits", + "rand", + "rand_pcg", + "serde", + "special", +] + +[[package]] +name = "rand_pcg" +version = "0.4.0" +dependencies = [ + "bincode", + "rand_core", + "serde", +] + +[[package]] +name = "rayon" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "serde" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "special" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24a65e074159b75dcf173a4733ab2188baac24967b5c8ec9ed87ae15fcbc7636" +dependencies = [ + "libc", +] + +[[package]] +name = "syn" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/patches/regex-lock.toml b/patches/regex-lock.toml new file mode 100644 index 00000000000..0e4a33b90ea --- /dev/null +++ b/patches/regex-lock.toml @@ -0,0 +1,439 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +dependencies = [ + "memchr", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bzip2" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "docopt" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f3f119846c823f9eafcf953a8f6ffb6ed69bf6240883261a7f13b634579a51f" +dependencies = [ + "lazy_static", + "regex 1.8.3", + "serde", + "strsim", +] + +[[package]] +name = "filetime" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "windows-sys", +] + +[[package]] +name = "getrandom" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.144" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" + +[[package]] +name = "libpcre-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ff3dd28ba96d6fe6752882f2f1b25ba8e1646448e79042442347cf3a92a6666" +dependencies = [ + "bzip2", + "libc", + "pkg-config", + "tar", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memmap" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "onig" +version = "3.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5eeb268a4620c74ea5768c6d2ccd492d60a47a8754666b91a46bfc35cd4d1ba" +dependencies = [ + "bitflags", + "lazy_static", + "libc", + "onig_sys", +] + +[[package]] +name = "onig_sys" +version = "68.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "195ebddbb56740be48042ca117b8fb6e0d99fe392191a9362d82f5f69e510379" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" + +[[package]] +name = "proc-macro2" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quickcheck" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" +dependencies = [ + "rand", +] + +[[package]] +name = "quote" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.7.2" +dependencies = [ + "aho-corasick", + "lazy_static", + "memchr", + "quickcheck", + "rand", + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81ca098a9821bd52d6b24fd8b10bd081f47d39c22778cafaa75a2857a62c6390" +dependencies = [ + "regex-syntax 0.7.2", +] + +[[package]] +name = "regex-benchmark" +version = "0.1.0" +dependencies = [ + "cc", + "cfg-if 0.1.10", + "docopt", + "lazy_static", + "libc", + "libpcre-sys", + "memmap", + "onig", + "pkg-config", + "regex 1.7.2", + "regex-syntax 0.6.29", + "serde", +] + +[[package]] +name = "regex-debug" +version = "0.1.0" +dependencies = [ + "docopt", + "regex 1.7.2", + "regex-syntax 0.6.29", + "serde", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" + +[[package]] +name = "regex-syntax" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" + +[[package]] +name = "rure" +version = "0.2.2" +dependencies = [ + "libc", + "regex 1.7.2", +] + +[[package]] +name = "serde" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tar" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" +dependencies = [ + "filetime", + "libc", + "xattr", +] + +[[package]] +name = "unicode-ident" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "xattr" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc" +dependencies = [ + "libc", +] diff --git a/build_sysroot/Cargo.lock b/patches/stdlib-lock.toml similarity index 100% rename from build_sysroot/Cargo.lock rename to patches/stdlib-lock.toml diff --git a/scripts/rustup.sh b/scripts/rustup.sh index 6b446aafb7b..e62788f2e50 100755 --- a/scripts/rustup.sh +++ b/scripts/rustup.sh @@ -33,11 +33,9 @@ case $1 in ./clean_all.sh ./y.sh prepare - - (cd download/sysroot && cargo update && cargo fetch && cp Cargo.lock ../../build_sysroot/) ;; "commit") - git add rust-toolchain build_sysroot/Cargo.lock + git add rust-toolchain git commit -m "Rustup to $(rustc -V)" ;; "push") From eb3e8bb7d729a2df19b1fe2a6a6d7b5e43673807 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 29 May 2023 12:16:33 +0000 Subject: [PATCH 81/89] Move some profile settings out of the stdlib cargo workspace patch --- build_system/build_sysroot.rs | 10 +++++++++- build_system/prepare.rs | 8 -------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 1045023c361..5ea34f758b9 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -4,7 +4,9 @@ use std::process::{self, Command}; use super::path::{Dirs, RelPath}; use super::rustc_info::{get_file_name, get_rustc_version}; -use super::utils::{remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler}; +use super::utils::{ + is_ci, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler, +}; use super::{CodegenBackend, SysrootKind}; static DIST_DIR: RelPath = RelPath::DIST; @@ -272,10 +274,16 @@ fn build_clif_sysroot_for_triple( } compiler.rustflags += &rustflags; let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs); + build_cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode + if is_ci() { + // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway + build_cmd.env("CARGO_BUILD_INCREMENTAL", "false"); + } if channel == "release" { build_cmd.arg("--release"); } build_cmd.arg("--features").arg("compiler-builtins-no-asm backtrace panic-unwind"); + build_cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "true"); build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); if compiler.triple.contains("apple") { build_cmd.env("CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO", "packed"); diff --git a/build_system/prepare.rs b/build_system/prepare.rs index c6bc796f3a9..350c3ad8fdc 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -37,14 +37,6 @@ rustc-std-workspace-core = { path = "./library/rustc-std-workspace-core" } rustc-std-workspace-alloc = { path = "./library/rustc-std-workspace-alloc" } rustc-std-workspace-std = { path = "./library/rustc-std-workspace-std" } -[profile.dev] -lto = "off" - -[profile.release] -debug = true -incremental = true -lto = "off" - # Mandatory for correctly compiling compiler-builtins [profile.dev.package.compiler_builtins] debug-assertions = false From 6b9af8cb36d2bc1ae57768e3c8703093870d919f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 29 May 2023 13:18:41 +0000 Subject: [PATCH 82/89] Disable all incremental compilation for CARGO_BUILD_INCREMENTAL=false --- build_system/build_backend.rs | 8 ++------ build_system/build_sysroot.rs | 8 ++------ build_system/utils.rs | 10 ++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index b88489a341c..6855c1a7fc5 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use super::path::{Dirs, RelPath}; use super::rustc_info::get_file_name; -use super::utils::{is_ci, is_ci_opt, CargoProject, Compiler}; +use super::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler}; pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif"); @@ -14,8 +14,7 @@ pub(crate) fn build_backend( use_unstable_features: bool, ) -> PathBuf { let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs); - - cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode + maybe_incremental(&mut cmd); let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default(); @@ -23,9 +22,6 @@ pub(crate) fn build_backend( // Deny warnings on CI rustflags += " -Dwarnings"; - // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway - cmd.env("CARGO_BUILD_INCREMENTAL", "false"); - if !is_ci_opt() { cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true"); cmd.env("CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS", "true"); diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 5ea34f758b9..04cd3894adc 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -5,7 +5,7 @@ use std::process::{self, Command}; use super::path::{Dirs, RelPath}; use super::rustc_info::{get_file_name, get_rustc_version}; use super::utils::{ - is_ci, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler, + maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler, }; use super::{CodegenBackend, SysrootKind}; @@ -274,11 +274,7 @@ fn build_clif_sysroot_for_triple( } compiler.rustflags += &rustflags; let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs); - build_cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode - if is_ci() { - // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway - build_cmd.env("CARGO_BUILD_INCREMENTAL", "false"); - } + maybe_incremental(&mut build_cmd); if channel == "release" { build_cmd.arg("--release"); } diff --git a/build_system/utils.rs b/build_system/utils.rs index e7fcb2644d7..41fc366e290 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -258,3 +258,13 @@ pub(crate) fn is_ci() -> bool { pub(crate) fn is_ci_opt() -> bool { env::var("CI_OPT").is_ok() } + +pub(crate) fn maybe_incremental(cmd: &mut Command) { + if is_ci() || std::env::var("CARGO_BUILD_INCREMENTAL").map_or(false, |val| val == "false") { + // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway + cmd.env("CARGO_BUILD_INCREMENTAL", "false"); + } else { + // Force incr comp even in release mode unless in CI or incremental builds are explicitly disabled + cmd.env("CARGO_BUILD_INCREMENTAL", "true"); + } +} From d0ea8bbc5e8dcb2018a248ee9d88a02ce2319b3c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 29 May 2023 13:41:55 +0000 Subject: [PATCH 83/89] Only copy library dir for stdlib When building as part of rust, the sysroot source dir is symlinked to the main source dir, which contains the build dir to which we are likely copying. --- build_system/prepare.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 350c3ad8fdc..748d92614b6 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -268,7 +268,12 @@ pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, ta remove_dir_if_exists(target_dir); fs::create_dir_all(target_dir).unwrap(); - copy_dir_recursively(source_dir, target_dir); + if crate_name == "stdlib" { + fs::create_dir(target_dir.join("library")).unwrap(); + copy_dir_recursively(&source_dir.join("library"), &target_dir.join("library")); + } else { + copy_dir_recursively(source_dir, target_dir); + } init_git_repo(target_dir); From bcac2220134a0b6ca858b674c00ad809c2ed446a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 4 Jun 2023 15:41:43 +0000 Subject: [PATCH 84/89] Lazily patch the standard library --- build_system/build_sysroot.rs | 27 ++++++--------------------- build_system/main.rs | 23 ++++++++++++++++------- build_system/prepare.rs | 14 ++++---------- build_system/rustc_info.rs | 6 ------ 4 files changed, 26 insertions(+), 44 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 04cd3894adc..74bba9ed5eb 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -1,9 +1,9 @@ use std::fs; use std::path::{Path, PathBuf}; -use std::process::{self, Command}; +use std::process::Command; use super::path::{Dirs, RelPath}; -use super::rustc_info::{get_file_name, get_rustc_version}; +use super::rustc_info::get_file_name; use super::utils::{ maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler, }; @@ -158,7 +158,6 @@ impl SysrootTarget { } pub(crate) static STDLIB_SRC: RelPath = RelPath::BUILD.join("stdlib"); -pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = STDLIB_SRC.join("rustc_version"); pub(crate) static STANDARD_LIBRARY: CargoProject = CargoProject::new(&STDLIB_SRC.join("library/sysroot"), "stdlib_target"); pub(crate) static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup"); @@ -222,24 +221,6 @@ fn build_clif_sysroot_for_triple( mut compiler: Compiler, cg_clif_dylib_path: &CodegenBackend, ) -> SysrootTarget { - match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) { - Err(e) => { - eprintln!("Failed to get rustc version for patched sysroot source: {}", e); - eprintln!("Hint: Try `./y.sh prepare` to patch the sysroot source"); - process::exit(1); - } - Ok(source_version) => { - let rustc_version = get_rustc_version(&compiler.rustc); - if source_version != rustc_version { - eprintln!("The patched sysroot source is outdated"); - eprintln!("Source version: {}", source_version.trim()); - eprintln!("Rustc version: {}", rustc_version.trim()); - eprintln!("Hint: Try `./y.sh prepare` to update the patched sysroot source"); - process::exit(1); - } - } - } - let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] }; if let Some(rtstartup_target_libs) = build_rtstartup(dirs, &compiler) { @@ -302,6 +283,10 @@ fn build_clif_sysroot_for_triple( } fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option { + if !super::config::get_bool("keep_sysroot") { + super::prepare::prepare_stdlib(dirs, &compiler.rustc); + } + if !compiler.triple.ends_with("windows-gnu") { return None; } diff --git a/build_system/main.rs b/build_system/main.rs index 06395eb141c..d51e5027cf3 100644 --- a/build_system/main.rs +++ b/build_system/main.rs @@ -126,6 +126,22 @@ fn main() { } } + let current_dir = std::env::current_dir().unwrap(); + out_dir = current_dir.join(out_dir); + + if command == Command::Prepare { + prepare::prepare(&path::Dirs { + source_dir: current_dir.clone(), + download_dir: download_dir + .map(|dir| current_dir.join(dir)) + .unwrap_or_else(|| out_dir.join("download")), + build_dir: PathBuf::from("dummy_do_not_use"), + dist_dir: PathBuf::from("dummy_do_not_use"), + frozen, + }); + process::exit(0); + } + let rustup_toolchain_name = match (env::var("CARGO"), env::var("RUSTC"), env::var("RUSTDOC")) { (Ok(_), Ok(_), Ok(_)) => None, (Err(_), Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()), @@ -158,8 +174,6 @@ fn main() { .unwrap_or_else(|| bootstrap_host_compiler.triple.clone()); // FIXME allow changing the location of these dirs using cli arguments - let current_dir = std::env::current_dir().unwrap(); - out_dir = current_dir.join(out_dir); let dirs = path::Dirs { source_dir: current_dir.clone(), download_dir: download_dir @@ -181,11 +195,6 @@ fn main() { std::fs::File::create(target).unwrap(); } - if command == Command::Prepare { - prepare::prepare(&dirs, &bootstrap_host_compiler.rustc); - process::exit(0); - } - env::set_var("RUSTC", "rustc_should_be_set_explicitly"); env::set_var("RUSTDOC", "rustdoc_should_be_set_explicitly"); diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 748d92614b6..77f7175b786 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -3,24 +3,21 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; -use super::build_sysroot::{STDLIB_SRC, SYSROOT_RUSTC_VERSION}; +use super::build_sysroot::STDLIB_SRC; use super::path::{Dirs, RelPath}; -use super::rustc_info::{get_default_sysroot, get_rustc_version}; +use super::rustc_info::get_default_sysroot; use super::utils::{ copy_dir_recursively, git_command, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait, }; -pub(crate) fn prepare(dirs: &Dirs, rustc: &Path) { +pub(crate) fn prepare(dirs: &Dirs) { RelPath::DOWNLOAD.ensure_exists(dirs); super::tests::RAND_REPO.fetch(dirs); super::tests::REGEX_REPO.fetch(dirs); super::tests::PORTABLE_SIMD_REPO.fetch(dirs); - - // FIXME do this on the fly? - prepare_stdlib(dirs, rustc); } -fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { +pub(crate) fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust"); assert!(sysroot_src_orig.exists()); @@ -50,9 +47,6 @@ codegen-units = 10000 "#, ) .unwrap(); - - let rustc_version = get_rustc_version(rustc); - fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap(); } pub(crate) struct GitRepo { diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 42cec0c6935..5b71504e90a 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -1,12 +1,6 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; -pub(crate) fn get_rustc_version(rustc: &Path) -> String { - let version_info = - Command::new(rustc).stderr(Stdio::inherit()).args(&["-V"]).output().unwrap().stdout; - String::from_utf8(version_info).unwrap() -} - pub(crate) fn get_host_triple(rustc: &Path) -> String { let version_info = Command::new(rustc).stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout; From 8c1c84d79e26e5250d3ad1ee894843c01785787a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 5 Jun 2023 13:59:08 +0000 Subject: [PATCH 85/89] Copy Cargo.lock over in ./y.sh prepare This makes it easier for ./x.py to vendor all dependencies --- build_system/prepare.rs | 21 +++++++++++++-------- build_system/tests.rs | 10 +++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 77f7175b786..e31e39a483f 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -47,6 +47,10 @@ codegen-units = 10000 "#, ) .unwrap(); + + let source_lockfile = RelPath::PATCHES.to_path(dirs).join("stdlib-lock.toml"); + let target_lockfile = STDLIB_SRC.to_path(dirs).join("Cargo.lock"); + fs::copy(source_lockfile, target_lockfile).unwrap(); } pub(crate) struct GitRepo { @@ -134,6 +138,15 @@ impl GitRepo { } } + let source_lockfile = + RelPath::PATCHES.to_path(dirs).join(format!("{}-lock.toml", self.patch_name)); + let target_lockfile = download_dir.join("Cargo.lock"); + if source_lockfile.exists() { + fs::copy(source_lockfile, target_lockfile).unwrap(); + } else { + assert!(target_lockfile.exists()); + } + let actual_hash = format!("{:016x}", hash_dir(&download_dir)); if actual_hash != self.content_hash { println!( @@ -285,12 +298,4 @@ pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, ta apply_patch_cmd.arg(patch).arg("-q"); spawn_and_wait(apply_patch_cmd); } - - let source_lockfile = RelPath::PATCHES.to_path(dirs).join(format!("{crate_name}-lock.toml")); - let target_lockfile = target_dir.join("Cargo.lock"); - if source_lockfile.exists() { - fs::copy(source_lockfile, target_lockfile).unwrap(); - } else { - assert!(target_lockfile.exists()); - } } diff --git a/build_system/tests.rs b/build_system/tests.rs index d104efd61e5..733a572400b 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -100,7 +100,7 @@ pub(crate) static RAND_REPO: GitRepo = GitRepo::github( "rust-random", "rand", "50b9a447410860af8d6db9a208c3576886955874", - "98b2276210b30e43", + "446203b96054891e", "rand", ); @@ -110,7 +110,7 @@ pub(crate) static REGEX_REPO: GitRepo = GitRepo::github( "rust-lang", "regex", "32fed9429eafba0ae92a64b01796a0c5a75b88c8", - "d6af6507d565aa66", + "fcc4df7c5b902633", "regex", ); @@ -120,7 +120,7 @@ pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( "rust-lang", "portable-simd", "ad8afa8c81273b3b49acbea38cd3bcf17a34cf2b", - "1ba291009510070b", + "800548f8000e31bd", "portable-simd", ); @@ -156,6 +156,10 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ &LIBCORE_TESTS_SRC.to_path(&runner.dirs), ); + let source_lockfile = RelPath::PATCHES.to_path(&runner.dirs).join("coretests-lock.toml"); + let target_lockfile = LIBCORE_TESTS_SRC.to_path(&runner.dirs).join("Cargo.lock"); + fs::copy(source_lockfile, target_lockfile).unwrap(); + LIBCORE_TESTS.clean(&runner.dirs); if runner.is_native { From a691b14aeeea6de133c23050e33732b5fe620a7b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 5 Jun 2023 15:15:48 +0000 Subject: [PATCH 86/89] Allow skipping tests from the commandline --- build_system/main.rs | 8 ++++++++ build_system/tests.rs | 27 +++++++++++++++++++-------- build_system/usage.txt | 5 ++++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/build_system/main.rs b/build_system/main.rs index d51e5027cf3..41d0d6f2319 100644 --- a/build_system/main.rs +++ b/build_system/main.rs @@ -90,6 +90,7 @@ fn main() { let mut sysroot_kind = SysrootKind::Clif; let mut use_unstable_features = true; let mut frozen = false; + let mut skip_tests = vec![]; let mut use_backend = None; while let Some(arg) = args.next().as_deref() { match arg { @@ -115,6 +116,12 @@ fn main() { } "--no-unstable-features" => use_unstable_features = false, "--frozen" => frozen = true, + "--skip-test" => { + // FIXME check that all passed in tests actually exist + skip_tests.push(args.next().unwrap_or_else(|| { + arg_error!("--skip-test requires argument"); + })); + } "--use-backend" => { use_backend = Some(match args.next() { Some(name) => name, @@ -218,6 +225,7 @@ fn main() { channel, sysroot_kind, use_unstable_features, + &skip_tests.iter().map(|test| &**test).collect::>(), &cg_clif_dylib, &bootstrap_host_compiler, rustup_toolchain_name.as_deref(), diff --git a/build_system/tests.rs b/build_system/tests.rs index 733a572400b..08d8f708c7d 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -19,7 +19,7 @@ struct TestCase { } enum TestCaseCmd { - Custom { func: &'static dyn Fn(&TestRunner) }, + Custom { func: &'static dyn Fn(&TestRunner<'_>) }, BuildLib { source: &'static str, crate_types: &'static str }, BuildBinAndRun { source: &'static str, args: &'static [&'static str] }, JitBin { source: &'static str, args: &'static str }, @@ -27,7 +27,7 @@ enum TestCaseCmd { impl TestCase { // FIXME reduce usage of custom test case commands - const fn custom(config: &'static str, func: &'static dyn Fn(&TestRunner)) -> Self { + const fn custom(config: &'static str, func: &'static dyn Fn(&TestRunner<'_>)) -> Self { Self { config, cmd: TestCaseCmd::Custom { func } } } @@ -247,6 +247,7 @@ pub(crate) fn run_tests( channel: &str, sysroot_kind: SysrootKind, use_unstable_features: bool, + skip_tests: &[&str], cg_clif_dylib: &CodegenBackend, bootstrap_host_compiler: &Compiler, rustup_toolchain_name: Option<&str>, @@ -256,7 +257,7 @@ pub(crate) fn run_tests( get_default_sysroot(&bootstrap_host_compiler.rustc).join("lib/rustlib/src/rust"); assert!(stdlib_source.exists()); - if config::get_bool("testsuite.no_sysroot") { + if config::get_bool("testsuite.no_sysroot") && !skip_tests.contains(&"testsuite.no_sysroot") { let target_compiler = build_sysroot::build_sysroot( dirs, channel, @@ -271,6 +272,7 @@ pub(crate) fn run_tests( dirs.clone(), target_compiler, use_unstable_features, + skip_tests, bootstrap_host_compiler.triple == target_triple, stdlib_source.clone(), ); @@ -281,8 +283,10 @@ pub(crate) fn run_tests( eprintln!("[SKIP] no_sysroot tests"); } - let run_base_sysroot = config::get_bool("testsuite.base_sysroot"); - let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot"); + let run_base_sysroot = config::get_bool("testsuite.base_sysroot") + && !skip_tests.contains(&"testsuite.base_sysroot"); + let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot") + && !skip_tests.contains(&"testsuite.extended_sysroot"); if run_base_sysroot || run_extended_sysroot { let mut target_compiler = build_sysroot::build_sysroot( @@ -302,6 +306,7 @@ pub(crate) fn run_tests( dirs.clone(), target_compiler, use_unstable_features, + skip_tests, bootstrap_host_compiler.triple == target_triple, stdlib_source, ); @@ -320,20 +325,22 @@ pub(crate) fn run_tests( } } -struct TestRunner { +struct TestRunner<'a> { is_native: bool, jit_supported: bool, use_unstable_features: bool, + skip_tests: &'a [&'a str], dirs: Dirs, target_compiler: Compiler, stdlib_source: PathBuf, } -impl TestRunner { +impl<'a> TestRunner<'a> { fn new( dirs: Dirs, mut target_compiler: Compiler, use_unstable_features: bool, + skip_tests: &'a [&'a str], is_native: bool, stdlib_source: PathBuf, ) -> Self { @@ -360,6 +367,7 @@ impl TestRunner { is_native, jit_supported, use_unstable_features, + skip_tests, dirs, target_compiler, stdlib_source, @@ -372,7 +380,10 @@ impl TestRunner { let tag = tag.to_uppercase(); let is_jit_test = tag == "JIT"; - if !config::get_bool(config) || (is_jit_test && !self.jit_supported) { + if !config::get_bool(config) + || (is_jit_test && !self.jit_supported) + || self.skip_tests.contains(&config) + { eprintln!("[{tag}] {testname} (skipped)"); continue; } else { diff --git a/build_system/usage.txt b/build_system/usage.txt index 9d20cdca6a7..6d3b3a13d6e 100644 --- a/build_system/usage.txt +++ b/build_system/usage.txt @@ -3,7 +3,7 @@ The build system of cg_clif. USAGE: ./y.sh prepare [--out-dir DIR] [--download-dir DIR] ./y.sh build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] - ./y.sh test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.sh test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] [--skip-test TESTNAME] ./y.sh abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] ./y.sh bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] @@ -32,6 +32,9 @@ OPTIONS: --frozen Require Cargo.lock and cache are up to date + --skip-test TESTNAME + Skip testing the TESTNAME test. The test name format is the same as config.txt. + --use-backend NAME Use the existing Cranelift (or other) backend of the rustc with which we built. Warning: This is meant for use in rust's CI only! From 485d7e129f5beb67e7769014959e07aff5989d22 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 5 Jun 2023 19:06:15 +0000 Subject: [PATCH 87/89] Remove outdated fixme --- build_system/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/build_system/main.rs b/build_system/main.rs index 41d0d6f2319..3bc78d5db94 100644 --- a/build_system/main.rs +++ b/build_system/main.rs @@ -180,7 +180,6 @@ fn main() { .or_else(|| config::get_value("target")) .unwrap_or_else(|| bootstrap_host_compiler.triple.clone()); - // FIXME allow changing the location of these dirs using cli arguments let dirs = path::Dirs { source_dir: current_dir.clone(), download_dir: download_dir From e9bd63af3cfc192f0f998debbf5ab3e597781cec Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 15 Jun 2023 17:14:49 +0000 Subject: [PATCH 88/89] Ignore -Clink-arg=-import-instr-limit --- src/config.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/config.rs b/src/config.rs index 263401e1c4b..9e92d656c76 100644 --- a/src/config.rs +++ b/src/config.rs @@ -82,6 +82,11 @@ impl BackendConfig { let mut config = BackendConfig::default(); for opt in opts { + if opt.starts_with("-import-instr-limit") { + // Silently ignore -import-instr-limit. It is set by rust's build system even when + // testing cg_clif. + continue; + } if let Some((name, value)) = opt.split_once('=') { match name { "mode" => config.codegen_mode = value.parse()?, From 8830dccd1d4c74f1f69b0d3bd982a3f1fcde5807 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 15 Jun 2023 17:45:30 +0000 Subject: [PATCH 89/89] Rustup to rustc 1.72.0-nightly (8c74a5d27 2023-06-14) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index c5149b2696b..fa3a10b9adc 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-06-13" +channel = "nightly-2023-06-15" components = ["rust-src", "rustc-dev", "llvm-tools"]