Skip to content

Instantly share code, notes, and snippets.

View stepancheg's full-sized avatar

Stepan Koltsov stepancheg

View GitHub Profile
//! Sample `lazy_static` function which provides an utility
//! similar to [lazy_static crate](https://github.com/rust-lang-nursery/lazy-static.rs)
//! but without any macros.
#![feature(alloc_static)]
use std::ptr;
use std::collections::HashMap;
use std::sync::atomic::*;
//! Sample `lazy_static` function which provides an utility
//! similar to [lazy_static crate](https://github.com/rust-lang-nursery/lazy-static.rs)
//! but without any macros.
#![feature(alloc_static)]
use std::ptr;
use std::collections::HashMap;
use std::sync::atomic::*;
use std::cell::UnsafeCell;
//! `singleton::<T>()` creates `T` once, and returns
//! a pointer to the same instances on subsequent calls.
#![feature(alloc_static)]
use std::ptr;
use std::sync::atomic::*;
use std::cell::UnsafeCell;
/// The function
diff --git a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java
@@ -1115,19 +1115,21 @@
}
}
- static String[] INDENTS = new String[0];
+ static volatile String[] INDENTS = new String[0];
@stepancheg
stepancheg / knights.py
Last active August 30, 2019 02:42
Knights
#!/usr/bin/env python3
from z3 import *
Person = Datatype("Person")
Person.declare("knight")
Person.declare("knave")
Person.declare("joker")
Person = Person.create()
#[test]
fn test_bool_1() {
do_conformance_test("tests/rust-testcases/bool.sky", "# Boolean tests\n\nTrue + 9223372036854775807 ### Type of parameters mismatch\n")
}
#[test]
fn test_struct_1() {
do_conformance_test("tests/rust-testcases/struct.sky", "# Struct tests\n\n# Comparison\nassert_(struct() == struct())\nassert_(struct(a=1) == struct(a=1))\nassert_(struct(a=1, b=False) == struct(a=1, b=False))\n\n# Order of fields is not important for comparison\nassert_(struct(a=1, b=2) == struct(b=2, a=1))\n\n# Inequality\nassert_(struct(a=2) != struct())\nassert_(struct() != struct(a=2))\nassert_(struct(a=2) != struct(a=1))\nassert_(struct(a=2) != struct(b=1))\nassert_(struct(a=1, b=2) != struct(a=1, b=\"2\"))\n")
}
@stepancheg
stepancheg / consistency.md
Last active May 11, 2019 22:45
In defence of the prefix await (and the prefix await?)

In defence of the prefix await (and the prefix await?)

TL;DR: prefix await is better because it is consistent with the rest of the language despite of its drawbacks.

There's ongoing discussion whether prefix or postfix await expression should be added to Rust.

use std::mem;
use std::pin::Pin;
use std::ops::DerefMut;
/// Self-referential struct
struct SelfRef<A, B>
where B: ?Sized, A: DerefMut, A::Target: Unpin,
{
/// Holds a pointer of type A
use std::mem;
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
struct Walk {
axis: u32,
positive: bool,
}
#[derive(Debug, Copy, Clone)]
struct Coord {
#!/usr/bin/env python
from __future__ import print_function
import time
s = ""
def f():
global s
s += "a"