Skip to content

Commit 28e35b5

Browse files
committed
merge master
2 parents 9a0dd55 + 943f7a1 commit 28e35b5

File tree

11 files changed

+219
-26
lines changed

11 files changed

+219
-26
lines changed

.devcontainer/devcontainer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
3+
{
4+
"name": "Existing Dockerfile",
5+
"build": {
6+
// Sets the run context to one level up instead of the .devcontainer folder.
7+
"context": "..",
8+
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
9+
"dockerfile": "../Dockerfile.dev"
10+
},
11+
"features": {
12+
},
13+
14+
// Features to add to the dev container. More info: https://containers.dev/features.
15+
// "features": {},
16+
17+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
18+
// "forwardPorts": [],
19+
20+
// Uncomment the next line to run commands after the container is created.
21+
// "postCreateCommand": "cat /etc/os-release",
22+
23+
// Configure tool-specific properties.
24+
// "customizations": {},
25+
26+
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
27+
"remoteUser": "root"
28+
}

.devcontainer/first-run-notice.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
👋 Welcome to Codespaces! You are on our Pivot-Lang's dev image.
2+
3+
You need to run `make devlinux && source ~/.bashrc` on the project root before start developing.
4+
5+
For any cargo build issues, please try `cargo clean`, and rerun the build command.

.github/workflows/docker_dev.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: docker_dev
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- release/*
7+
8+
9+
jobs:
10+
artifacts:
11+
name: docker_dev
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
submodules: true
17+
-
18+
name: Set up QEMU
19+
uses: docker/setup-qemu-action@v2
20+
-
21+
name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v2
23+
-
24+
name: Login to ali registry
25+
uses: docker/login-action@v2
26+
with:
27+
registry: registry.cn-hangzhou.aliyuncs.com
28+
username: ${{ secrets.DOCKERHUB_USERNAME }}
29+
password: ${{ secrets.DOCKERHUB_TOKEN }}
30+
-
31+
name: Build and push
32+
uses: docker/build-push-action@v4
33+
with:
34+
context: .
35+
push: true
36+
file: ./Dockerfile.dev
37+
tags: registry.cn-hangzhou.aliyuncs.com/pivot_studio/pivot_lang_dev:latest

.github/workflows/release.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ on:
44
branches:
55
- master
66
- release/*
7-
7+
paths:
8+
- '**.rs'
9+
- '**/Cargo.*'
10+
- '.github/workflows/release.yml'
11+
- '**.pi'
12+
- '**/Kagari.*'
13+
- 'codecov.yml'
814

915
jobs:
1016
artifacts:

Dockerfile.dev

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM mcr.microsoft.com/devcontainers/base:ubuntu AS runner
2+
COPY ./.devcontainer/first-run-notice.txt /tmp/scripts/
3+
RUN mv -f /tmp/scripts/first-run-notice.txt /usr/local/etc/vscode-dev-containers/
4+
COPY ./setup-llvm.sh .
5+
RUN apt-get update && apt-get install -y gnupg2 software-properties-common cmake
6+
RUN apt-get update && apt-get install -y lsb-release wget && apt-get clean all
7+
RUN ./setup-llvm.sh
8+
RUN apt update
9+
RUN apt install -y git libxml2 build-essential libunwind-dev
10+
RUN apt-get update
11+
12+
# Get Ubuntu packages
13+
RUN apt-get install -y \
14+
build-essential \
15+
curl
16+
17+
# Update new packages
18+
RUN apt-get update
19+
20+
COPY ./rust-toolchain .
21+
22+
# Get Rust
23+
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y --default-toolchain $(cat rust-toolchain)
24+
ENV PATH="/root/.cargo/bin:${PATH}"

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ vm:
1313
@cd vm && cargo build --release
1414

1515
vmdebug:
16+
@mkdir -p target/release
1617
@cd vm && cargo build
1718
@cp target/debug/libvm.a target/release/libvm.a
1819

book/src/dev-prepare.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,16 @@ make test
4646
如果上方命令都成功执行,那么恭喜你,你已经成功配置了开发环境
4747

4848

49+
## 使用github codespace 进行开发
50+
51+
使用github codespace进行开发的环境配置较为简单,但是请注意费用问题。
52+
53+
54+
点击以下链接即可创建一个包含pl开发环境的codespace
55+
56+
[create codespace](https://github.com/codespaces/new?machine=standardLinux32gb&repo=535925143&ref=master&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=SouthEastAsia)
57+
58+
创建完毕后,建议使用本地vscode打开codespace中的项目进行开发
59+
60+
61+

bors.toml

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

setup-llvm.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# This script install the correct LLVM release for Debian & Ubuntu distros.
4+
5+
set -eux
6+
7+
LLVM_VERSION=14
8+
DISTRO=$(lsb_release -is)
9+
VERSION=$(lsb_release -sr)
10+
DIST_VERSION="${DISTRO}_${VERSION}"
11+
12+
# Find the right repository name for the distro and version
13+
case "$DIST_VERSION" in
14+
Debian_9* ) REPO_NAME="deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch-$LLVM_VERSION main" ;;
15+
Debian_10* ) REPO_NAME="deb http://apt.llvm.org/buster/ llvm-toolchain-buster-$LLVM_VERSION main" ;;
16+
Debian_unstable ) REPO_NAME="deb http://apt.llvm.org/unstable/ llvm-toolchain-$LLVM_VERSION main" ;;
17+
Debian_testing ) REPO_NAME="deb http://apt.llvm.org/unstable/ llvm-toolchain-$LLVM_VERSION main" ;;
18+
Ubuntu_16.04 ) REPO_NAME="deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-$LLVM_VERSION main" ;;
19+
Ubuntu_18.04 ) REPO_NAME="deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-$LLVM_VERSION main" ;;
20+
Ubuntu_18.10 ) REPO_NAME="deb http://apt.llvm.org/cosmic/ llvm-toolchain-cosmic-$LLVM_VERSION main" ;;
21+
Ubuntu_19.04 ) REPO_NAME="deb http://apt.llvm.org/disco/ llvm-toolchain-disco-$LLVM_VERSION main" ;;
22+
Ubuntu_19.10 ) REPO_NAME="deb http://apt.llvm.org/eoan/ llvm-toolchain-eoan-$LLVM_VERSION main" ;;
23+
Ubuntu_20.04 ) REPO_NAME="deb http://apt.llvm.org/focal/ llvm-toolchain-focal-$LLVM_VERSION main" ;;
24+
Ubuntu_22.04 ) REPO_NAME="deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-$LLVM_VERSION main" ;;
25+
Ubuntu_22.10 ) REPO_NAME="deb http://apt.llvm.org/kinetic/ llvm-toolchain-kinetic-$LLVM_VERSION main" ;;
26+
* )
27+
echo "Distribution '$DISTRO' in version '$VERSION' is not supported by this script (${DIST_VERSION})."
28+
exit 2
29+
esac
30+
31+
# Add the right repository for the distro
32+
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
33+
add-apt-repository "${REPO_NAME}"
34+
apt-get update
35+
36+
# Install required packages
37+
apt-get install -y llvm-$LLVM_VERSION llvm-$LLVM_VERSION-* liblld-$LLVM_VERSION* libpolly-$LLVM_VERSION-dev

src/ast/diag.rs

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,16 @@ macro_rules! define_warn {
131131
};
132132
}
133133
};
134+
($(
135+
$ident:ident = $string_keyword:expr
136+
),*,) => {
137+
define_warn!($($ident = $string_keyword),*);
138+
};
134139
}
135140
define_warn! {
136-
UNREACHABLE_STATEMENT= "unreachable statement"
141+
UNREACHABLE_STATEMENT= "unreachable statement",
142+
UNUSED_VARIABLE = "unused variable",
143+
UNUSED_FUNCTION = "unused function",
137144
}
138145

139146
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -156,7 +163,7 @@ impl Display for DiagCode {
156163
}
157164
}
158165

159-
use lsp_types::{Diagnostic, DiagnosticSeverity, Url};
166+
use lsp_types::{Diagnostic, DiagnosticSeverity, DiagnosticTag, Url};
160167

161168
use crate::Db;
162169

@@ -204,11 +211,23 @@ impl PLDiag {
204211
)
205212
.with_code(self.raw.code)
206213
.with_message(self.get_msg());
207-
let labels = vec![PLLabel {
208-
range: self.raw.range,
209-
file: path.to_string(),
210-
txt: Some(("here".to_string(), vec![])),
211-
}];
214+
let mut labels = vec![];
215+
self.raw
216+
.labels
217+
.iter()
218+
.find(|label| {
219+
label.range.start == self.raw.range.start
220+
&& self.raw.range.end == label.range.end
221+
&& label.file == path
222+
})
223+
.or_else(|| {
224+
labels.push(PLLabel {
225+
range: self.raw.range,
226+
file: path.to_string(),
227+
txt: Some(("here".to_string(), vec![])),
228+
});
229+
None
230+
});
212231

213232
for label in labels.iter().chain(self.raw.labels.iter()) {
214233
let color = colors.next();
@@ -269,13 +288,22 @@ impl PLDiag {
269288
Some(PL_DIAG_SOURCE.to_string()),
270289
ERR_MSG[&code].to_string(),
271290
),
272-
DiagCode::Warn(code) => Diagnostic::new_with_code_number(
273-
self.raw.range.to_diag_range(),
274-
DiagnosticSeverity::WARNING,
275-
code as i32,
276-
Some(PL_DIAG_SOURCE.to_string()),
277-
WARN_MSG[&code].to_string(),
278-
),
291+
DiagCode::Warn(code) => {
292+
let mut warn = Diagnostic::new_with_code_number(
293+
self.raw.range.to_diag_range(),
294+
DiagnosticSeverity::WARNING,
295+
code as i32,
296+
Some(PL_DIAG_SOURCE.to_string()),
297+
WARN_MSG[&code].to_string(),
298+
);
299+
if code == WarnCode::UNUSED_FUNCTION
300+
|| code == WarnCode::UNUSED_VARIABLE
301+
|| code == WarnCode::UNREACHABLE_STATEMENT
302+
{
303+
warn.tags = Some(vec![DiagnosticTag::UNNECESSARY]);
304+
}
305+
warn
306+
}
279307
};
280308
let mut labels = vec![];
281309
self.raw.labels.iter().for_each(|label| {

0 commit comments

Comments
 (0)