Skip to content

Instantly share code, notes, and snippets.

View stepancheg's full-sized avatar

Stepan Koltsov stepancheg

View GitHub Profile
WARNING: ThreadSanitizer: data race (pid=28298)
Read of size 8 at 0x7b2000009030 by thread T32:
#0 _$LT$futures_channel..mpsc..queue..Queue$LT$T$GT$$u20$as$u20$core..ops..drop..Drop$GT$::drop::h6ca263cc39fadd8c queue.rs:172 (mpsc-22c621302f3d0cb3:x86_64+0x100038970)
#1 core::ptr::drop_in_place::h2deddc3643535d3f ptr.rs:194 (mpsc-22c621302f3d0cb3:x86_64+0x10001f8a8)
#2 core::ptr::drop_in_place::hb8c0f16a42964511 ptr.rs:194 (mpsc-22c621302f3d0cb3:x86_64+0x10002306c)
#3 _$LT$alloc..sync..Arc$LT$T$GT$$GT$::drop_slow::h79802a659643aa5c sync.rs:541 (mpsc-22c621302f3d0cb3:x86_64+0x100086670)
#4 _$LT$alloc..sync..Arc$LT$T$GT$$u20$as$u20$core..ops..drop..Drop$GT$::drop::ha9c0b5652212e54d sync.rs:994 (mpsc-22c621302f3d0cb3:x86_64+0x100087c6f)
#5 core::ptr::drop_in_place::hb76255f19666d440 ptr.rs:194 (mpsc-22c621302f3d0cb3:x86_64+0x100023018)
#6 core::ptr::drop_in_place::h2041ea1c39dc0817 ptr.rs:194 (mpsc-22c621302f3d0cb3:x86_64+0x10001ef5a)
#7 mpsc::send_one_two_three::_$u7b$$u7b$closu

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
#![feature(system_time_display_iso_8601)]
#![feature(libc)]
extern crate libc;
use std::mem;
use std::time::SystemTime;
use std::slice;
use std::str;
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 =
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)
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
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
def foo():
a = []
b = []
c = []
def aa():
# This works
a.append(1)
def bb():
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();
@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] }