Skip to content

Instantly share code, notes, and snippets.

View stepancheg's full-sized avatar

Stepan Koltsov stepancheg

View GitHub Profile
struct CyclicBarrierShared {
count: u32,
mutex: Mutex<(u32, bool)>,
condv: Condvar,
}
struct CyclicBarrier {
shared: Arc<CyclicBarrierShared>,
}
@stepancheg
stepancheg / xx.ll
Last active June 29, 2017 23:00
--emit=llvm-ir
; ModuleID = 'xx.cgu-0.rs'
source_filename = "xx.cgu-0.rs"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin"
%str_slice = type { i8*, i64 }
%"alloc::vec::Vec<u8>" = type { %"alloc::raw_vec::RawVec<u8, alloc::heap::HeapAlloc>", [0 x i8], i64, [0 x i8] }
%"alloc::raw_vec::RawVec<u8, alloc::heap::HeapAlloc>" = type { %"core::ptr::Unique<u8>", [0 x i8], i64, [0 x i8], %"alloc::heap::HeapAlloc", [0 x i8] }
%"core::ptr::Unique<u8>" = type { %"core::nonzero::NonZero<*const u8>", [0 x i8], %"core::marker::PhantomData<u8>", [0 x i8] }
%"core::nonzero::NonZero<*const u8>" = type { i8*, [0 x i8] }
package demo;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;
public class ParkUnpark {
public static void main(String[] args) throws Exception {
AtomicInteger count = new AtomicInteger();
def foo():
a = []
b = []
c = []
def aa():
# This works
a.append(1)
def bb():
module Main
-- Definition of what it means for List to be sorted
data Sorted : (v : List Nat) -> Type
where
-- empty list is always sorted
EmptySorted : Sorted []
-- list of one element is always sorted
OneSorted : (a : Nat) -> Sorted [a]
-- list of two or more element is sorted iff both are true
module Main
-- predicate is true for each list element
data Foreach : (Nat -> Type) -> List Nat -> Type
where
ForeachEmpty : (pred : Nat -> Type) -> Foreach pred []
ForeachRec : (pred : Nat -> Type) -> (e : Nat) -> (rem : List Nat) -> Foreach pred rem ->
Foreach pred (e :: rem)
-- predicate for list element count
open import Data.List
open import Data.Nat
open import Relation.Binary.PropositionalEquality
open import Function
open import Data.Product
open import Data.Sum
data _▶_≡_ {A : Set}(x : A) : List A → List A → Set where
here : ∀ {xs} → x ▶ xs ≡ (x ∷ xs)
data Zzz : List Nat -> List Nat -> Type
where
SameArg : Zzz l l
DiffArg : Zzz a b
helperFunc : (xs, ys : List Nat) -> Zzz xs ys
helperFunc = ?helperFunc
thisWorks : (xs, ys : List Nat) -> Nat
thisWorks xs ys =
#![feature(system_time_display_iso_8601)]
#![feature(libc)]
extern crate libc;
use std::mem;
use std::time::SystemTime;
use std::slice;
use std::str;

Here below there is a couple of thoughts about metaprogramming in Rust, the area of compile-time reflection.

Is it not a proposal, just an idea of what I would like to have.

There are several problems which are not solvable in modern rust, except with programmatic macros (e. g. serde).

  • automatic to and from JSON mapping
  • automatic database mapping (ORM)
  • binary struct serializers
  • custom fmt::Debug derive which skips fields which are not formattable